无法在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);