Froala 所见即所得编辑器 - Asp.net MVC

Froala WYSIWYG Editor - Asp.net MVC

我被利用了Froala WYSIWYG Editor。上传的图片已成功保存在正确的路径中,但未在编辑器中显示。

<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); 有什么问题?

更新:

我在一个区域使用这个编辑器,它接缝我必须改变 url。

我写了

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

而不是

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

但是问题还没有解决!!

我发现了问题。

必须写

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