• MVC中使用KindEditor


    曾在一个论坛项目中,需要在mvc框架中使用KindEditor来编辑文章,由于当时也是刚接触MVC框架,也很是头疼。

    后来经过多般努力,找到了适合自己的方法。

    首先是利用 @Html.TextArea()来生命一个文本域,在通过JS脚本来将 KindEditor绑定到文本域上,同时也可以通过css样式来控制编辑器的格式。

     1 <script>
     2         KindEditor.ready(function (K) {
     3             var editor1 = K.create('#content1', {
     4                 cssPath: 'editor/plugins/code/prettify.css',
     5                 uploadJson: 'editor/asp.net/upload_json.ashx',
     6                 fileManagerJson: 'editor/asp.net/file_manager_json.ashx',
     7                 allowFileManager: true,
     8                 afterCreate: function () {
     9                     var self = this;
    10                     K.ctrl(document, 13, function () {
    11                         self.sync();
    12                         K('form[name=example]')[0].submit();
    13                     });
    14                     K.ctrl(self.edit.doc, 13, function () {
    15                         self.sync();
    16                         K('form[name=example]')[0].submit();
    17                     });
    18                 }
    19             });
    20             prettyPrint();
    21         });
    22     </script>
    1  <td class="td2">
    2                 @Html.TextArea("content1", new { Class = "www" })@*
    3                 @Html.TextAreaFor(mod => mod.AModel.Loginformation, new { Class="www"})*@
    4                 @Html.ValidationMessage("nullerror")
    5             </td>
    1   string textvalue = Request.Params["content1"].ToString();

    到Controllers文件中使用Request.Params[].ToString();来取得编辑器的值。

    同时Controllers文件中方法,在接收和使用编辑器的值时我们要用  [ValidateInput(false)]在定义当方法,因为VS在MVC中有严格的安全验证,只有通过  [ValidateInput(false)]的定义才能使文本编辑器的值顺利保存。

  • 相关阅读:
    安装IIS的郁闷之旅
    设置WPF窗口相对于非WPF窗口的位置
    钓鱼记
    java拾遗
    人间四月芳菲尽
    [linux] x server can not start under VMWare
    如果没有开源软件没有免费软件,这个世界会怎么样?评[盖茨北大演讲遭遇开源人士抗议]
    程序员的面包
    2007中国软件英雄会-七年的等待
    sysbench安装
  • 原文地址:https://www.cnblogs.com/qzzy/p/2949937.html
Copyright © 2020-2023  润新知