无法在MVC的tinymce编辑器中上传图像? [英] Unable to upload image in tinymce editor in MVC ?

查看:91
本文介绍了无法在MVC的tinymce编辑器中上传图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生/女士,



这是我上传图片的代码。



Dear sir/madam,

this is my code for uploading the image in tinymce.

<script>
tinymce.init({
selector: '#Content',
height: 500,
theme: 'modern',
skin: "lightgray",
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 imagetools'
],
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,
images_upload_url: '/News/upload',
automatic_uploads: true
});
</script>





------这是控制器代码-------- -------



------this is controller code---------------

public ActionResult Upload()
       {
           var file = Request.Files["file"];
           //string extension = Path.GetExtension(file.FileName);
           //string fileid = Guid.NewGuid().ToString();
           //fileid = Path.ChangeExtension(fileid, extension);
           var filename1 = Path.GetFileName(file.FileName);
           string location = Server.MapPath(@"~\Uploads\" +filename1);
           file.SaveAs(location);

           return Json(new { location },JsonRequestBehavior.AllowGet);
       }





问题是图像被保存在文件夹中但未显示在文件夹中编辑。

感谢您提前的帮助。



我尝试了什么:



i也试图使用uplodify上传文件,但它无效。



the problem is that the image is getting saved in the folder but is not shown in the editor.
thanks for your help in advance.

What I have tried:

i also tried to upload file using uplodify but its not working.

推荐答案

可能是因为你要返回本地路径保存图像的服务器,而不是URL。



将return语句更改为:
Probably because you're returning the local path on the server where the image was saved, rather than the URL.

Change the return statement to:
return Json(new { location = Url.Content("~/Uploads/" + filename1) }, JsonRequestBehavior.AllowGet);


这篇关于无法在MVC的tinymce编辑器中上传图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆