zoukankan      html  css  js  c++  java
  • 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)]的定义才能使文本编辑器的值顺利保存。

  • 相关阅读:
    echarts 算百分比与js toFixed算出来的百分比不一致的问题。
    VUE, Vue Router Tab 显示动态页签名称。
    [日常坑]前端j's数据导出excel,导出的文件损坏
    [最新 | Build 3211]Sublime Text 2.x, 3.x 许可License集合
    图片滤波
    electron-ipc通信性能分析
    设计vue3的请求实体工厂
    canvas-修改图片亮度
    canvas性能-drawImage渲染图片
    基于windows配置gitlab-runner
  • 原文地址:https://www.cnblogs.com/qzzy/p/2949937.html
Copyright © 2011-2022 走看看