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

转载于:https://www.cnblogs.com/qzzy/archive/2013/03/08/2949937.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值