[英]TinyMCE - local image upload
每次將本地圖像上傳到TinyMCE表單時,我都會遇到一個奇怪的錯誤-頁面會重新加載。 使用TinyMCE 4.7.13和ASP MVC 。
我的代碼:
tinymce.init({
selector: '.formatedtext',
branding: false,
plugins: 'code,emoticons,lists,advlist,autolink,autoresize,autosave,codesample,textcolor,colorpicker,fullscreen,hr,image,link,media,preview,searchreplace,table,textpattern,wordcount,imagetools',
toolbar: 'image,code,emoticons,bulllist,numlist,restoredraft,codesample,forecolor,backcolor,fullscreen,preview,searchreplace',
width: '100%',
language: 'cs',
browser_spellcheck: true,
image_advtab: true,
paste_data_images: true,
automatic_uploads: true,
file_picker_types: 'image',
images_upload_url: '/TinyMce/TinyMceUpload'
});
TinyMce控制器中的操作:
[HttpPost]
public ActionResult TinyMceUpload(HttpPostedFileBase file) {
//Response.AppendHeader("Access-Control-Allow-Origin", "*");
string loc = SaveFile(Server.MapPath("~/Uploads/UsersContent/"), file);
return Json(new {
location = loc
});
}
SaveFile
的定義和運行位置。
問題是圖像已加載,成功保存,但是一旦加載,頁面就會重新加載。
Index.cshtml
<script>
tinymce.init({
selector: "textarea",
theme: "modern",
paste_data_images: true,
plugins: [
"advlist autolink lists link image charmap print preview hr anchor pagebreak",
"searchreplace wordcount visualblocks visualchars code fullscreen",
"insertdatetime media nonbreaking save table contextmenu directionality",
"emoticons template paste textcolor colorpicker textpattern"
],
toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
toolbar2: "print preview media | forecolor backcolor emoticons",
image_advtab: true,
file_picker_callback: function (callback, value, meta) {
if (meta.filetype == 'image') {
$('#upload').trigger('click');
$('#upload').on('change', function () {
var file = this.files[0];
var reader = new FileReader();
reader.onload = function (e) {
callback(e.target.result, {
alt: ''
});
};
reader.readAsDataURL(file);
});
}
},
});
</script>
如果您上傳圖片,則可以直接在Base64 Encoder中的textarea圖片中顯示
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.