0
我可以使用TextAreaFor助手將html保存到數據庫,然後將其加載到呈現它的頁面上嗎?我可以使用TextAreaFor助手作爲html編輯器嗎?
我可以使用TextAreaFor助手將html保存到數據庫,然後將其加載到呈現它的頁面上嗎?我可以使用TextAreaFor助手作爲html編輯器嗎?
當然可以,但ASP.NET的請求過濾器默認情況下不允許傳入請求包含html,js等。因此,您需要爲模型的目標屬性禁用此選項。最好的辦法是用AllowHtmlAttribute
來標記房產。
public class YourViewModel
{
[AllowHtml]
public string description { get; set; }
}
,並在視圖渲染
@Html.Raw(Model.description)
另外,您可以禁用該操作的驗證要求如
[HttpPost]
[ValidateInput(false)]
public ActionResult YourAction(YourViewModel model)
{
}
,但它不是最好的解決辦法。
就像說明一樣,您不能將AllowHtmlAttribute應用於控制器操作,因爲它只能應用於屬性。 ([請參閱MSDN條目](http://msdn.microsoft.com/en-us/library/system.web.mvc.allowhtmlattribute(v = vs.108).aspx)。) –