2013-07-07 113 views

回答

1

當然可以,但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) 
{ 

} 

,但它不是最好的解決辦法。

+0

就像說明一樣,您不能將AllowHtmlAttribute應用於控制器操作,因爲它只能應用於屬性。 ([請參閱MSDN條目](http://msdn.microsoft.com/en-us/library/system.web.mvc.allowhtmlattribute(v = vs.108).aspx)。) –

相關問題