ASP.NET MVC3 使用kindeditor编辑器获取不到值

做开发真的是会遇到各种问题,如果不亲自尝试,不动手,很难发现问题。

下面我们说下在MVC中的用法

1,首先引入js文件

   <script type="text/javascript" src='@Url.Content("~/Content/editor/kindeditor-min.js")'></script>
    <script type="text/javascript" src='@Url.Content("~/Content/editor/lang/zh_CN.js")'></script>  
var editor; //
    KindEditor.ready(function (K) {
    editor = K.create('#Content', { filterMode: true,
        uploadJson: '@Url.Content("~/Content/editor/asp.net/upload_json.ashx")',
        fileManagerJson: '@Url.Content("~/Contenteditor/asp.net/file_manager_json.ashx")',
        afterBlur: function () { editor.sync(); },//MVC中不加这句取不到值
        allowFileManager: true
    }); //创建在线编辑器
});

2,前台页面代码

     @Html.TextAreaFor(c => c.Content, new { style = "600px;height:400px" });

3,后台页面代码

     [HttpPost]
        [ValidateInput(false)]若没有此行代码,会报错
        public virtual ActionResult EditDocument(DocumentModel documentModel)
        {
            if (ModelState.IsValid)
            {
              
                documentModel.Content = documentModel.Content.HtmlDecode().ToLegalContentHtml();

            }
            return View("EditDocument", documentModel);
        }
afterBlur: function () { editor.sync(); },这一行代码。
那么这个 this.sync(); 函数是干嘛的呢?简单的说:这个函数就是同步KindEditor的值到textarea文本框。
官方解释:
sync()
将编辑器的内容设置到原来的textarea控件里。
参数: 无
返回: KEditor
地址:http://www.kindsoft.net/docs/editor.html#sync

文件包下载

原文地址:https://www.cnblogs.com/zlzly/p/3725176.html