本文介紹了如何在 mvc5 中使用 allowhtml 屬性進行操作的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我正在開發一個 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="http://cdn.ckeditor.com/4.5.9/standard/ckeditor.js"></script>
<script>
CKEDITOR.replace('Message');
</script>
}
這篇關于如何在 mvc5 中使用 allowhtml 屬性進行操作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!