每次将本地图像上传到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
定义并运作的地方。
问题是图像已加载,成功保存,但一旦加载页面重新加载。
答案 0 :(得分:0)
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编码器的textarea图像中