如何在Mvc5中使用allowhtml属性进行操作 [英] how to use allowhtml attribute for an action in mvc5

查看:107
本文介绍了如何在Mvc5中使用allowhtml属性进行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个mvc 5项目,我想使用ckEditor来输入数据,因此在此编辑器中,我可以插入数据后保存了数据

,但是在使
出错时,它会出错
请参阅Imaage

I am developing an mvc 5 project and I want to use ckEditor for input data so in this editor I saved data
after I could insert data but when dispalying it has an error See Imaage

推荐答案

您可以将 AllowHtml 属性应用于在视图模型类中保存标记的属性。

You can apply AllowHtml attribute to the property which holds the markup in your view model class.

public class CreatePost
{
  public string PostTitle {set;get;}
  [AllowHtml]
  public string PostContent { set;get;}
}

并在HttpPost操作中使用此视图模型

And use this view model in your HttpPost action method and everything will work fine.

[HttpPost]
public ActionResult Create(CreatePost viewModel)
{
  // Check viewModel.PostContent property
  // to do  : Return something
}

现在只需确保您正在使用此属性来构建te与CKEditor一起使用的xt区域

Now just make sure you are using this property to build the text area to be used with CKEditor

@model CreatePost
@using (Html.BeginForm())
{    
    @Html.TextBoxFor(s => s.PostTitle)
    @Html.TextAreaFor(s=>s.PostContent)
    <input type="submit" />
}
@section Scripts
{
    <script src="//cdn.ckeditor.com/4.5.9/standard/ckeditor.js"></script>
    <script>
       CKEDITOR.replace('Message');
    </script>
}

这篇关于如何在Mvc5中使用allowhtml属性进行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆