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)]的定义才能使文本编辑器的值顺利保存。

  • 相关阅读:
    github上删除一个项目或者reposity
    java中二维数组的复制克隆
    Ajax学习笔记【精心收藏】
    CSS学习笔记总结篇【精心收藏】
    细说ajax
    JS一秒区分clientX,offsetX,screenX,pageX之间关系
    HTML5 离线应用程序 接口实现离线数据缓存【精心收藏】
    HTML5 Video标签
    【知识分享】 Web页面中5种超酷的Hover效果
    HTML5 音频audio 和视频video实用基础教程
  • 原文地址:https://www.cnblogs.com/qzzy/p/2949937.html
Copyright © 2011-2022 走看看