how to use allowhtml attribute for an action in mvc5(如何在 mvc5 中使用 allowhtml 属性进行操作)
问题描述
我正在开发一个 mvc 5 项目,我想使用 ckEditor 输入数据,所以在这个编辑器中我保存了数据
在我可以插入数据但显示时它有一个错误查看图片
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
}
现在只需确保您使用此属性来构建要与 CKEditor 一起使用的文本区域
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="Ly9jZG4uY2tlZGl0b3IuY29tLzQuNS45L3N0YW5kYXJkL2NrZWRpdG9yLmpz"></script>
<script>
CKEDITOR.replace('Message');
</script>
}
这篇关于如何在 mvc5 中使用 allowhtml 属性进行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 mvc5 中使用 allowhtml 属性进行操作


- C#MongoDB使用Builders查找派生对象 2022-09-04
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01