最佳答案
您可以将 AllowHtml
特性应用于在您的 View 模型类中保存标记的属性。
public class CreatePost
{
public string PostTitle {set;get;}
[AllowHtml]
public string PostContent { set;get;}
}
并在您的 HttpPost 操作方法中使用此 View 模型,一切都会正常工作。
[HttpPost]
public ActionResult Create(CreatePost viewModel)
{
// Check viewModel.PostContent property
// to do : Return something
}
现在只需确保您正在使用此属性来构建要与 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>
}
关于c# - 如何在 mvc5 中为 Action 使用 allowhtml 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37886474/