Javascript TinyMCE-本地图像上载
每次将本地图像上传到TinyMCE表单时,我都会遇到一个奇怪的错误-页面重新加载。使用TinyMCE 4.7.13和ASP MVC 我的代码:Javascript TinyMCE-本地图像上载,javascript,asp.net-mvc,tinymce,Javascript,Asp.net Mvc,Tinymce,每次将本地图像上传到TinyMCE表单时,我都会遇到一个奇怪的错误-页面重新加载。使用TinyMCE 4.7.13和ASP MVC 我的代码: tinymce.init({ selector: '.formatedtext', branding: false, plugins: 'code,emoticons,lists,advlist,autolink,autoresize,autosave,codesample,textcolor,colorpicker,fullsc
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编码器的textarea图像中,如果上载图像否,则取消文件选择器回调