2016-09-06 178 views
1

我被用於Froala WYSIWYG Editor。已上傳的圖像已成功保存在正確的路徑中,但未在編輯器中顯示。Froala WYSIWYG編輯器 - Asp.net MVC

<script> 
     $(function() { 
      $('#PostDesc').froalaEditor({ 
       imageButtons: ["removeImage", "replaceImage", "linkImage"], 
       borderColor: '#00008b', 
       imageUploadURL: '@Url.Action("FroalaUploadImage", "Posts")', 
       imageParams: { postId: "123" }, 
       enableScript: false, 
       fileUploadURL: '@Url.Action("FroalaUploadFile", "Posts")', 
       fileUploadParams: { postId: "123" } 
      }); 
     }); 
</script> 

操作:

[HttpPost] 
public ActionResult FroalaUploadImage(HttpPostedFileBase file, int? postId) 
{ 
    var fileName = Path.GetFileName(file.FileName); 
    var rootPath = Server.MapPath("~/img/Post/"); 
    file.SaveAs(Path.Combine(rootPath, fileName)); 
    return Json(new { link = "img/Post/" + fileName }, JsonRequestBehavior.AllowGet); 
} 

有什麼不對return Json(new { link = "img/Post/" + fileName }, JsonRequestBehavior.AllowGet);

更新:

我使用的區域這個編輯器和它接縫,我必須改變網址。

我寫

return Json(new UrlHelper(this.Request.RequestContext).Content("~/img/Post/" + fileName), JsonRequestBehavior.AllowGet); 

代替

return Json(new { link = "img/Post/" + fileName }, JsonRequestBehavior.AllowGet); 

,但問題沒有解決!

回答

1

我發現了這個問題。

必由之路寫道

return Json(new { link = new UrlHelper(Request.RequestContext).Content("~/img/Post/" + fileName) }, JsonRequestBehavior.AllowGet);