2011-08-04 39 views
1

我想在數據庫中輸入html並將其顯示爲html。我寫了我這樣的視圖模型:忽略html實體驗證的模型屬性

public class TemplateVM 
{ 
    [HiddenInput(DisplayValue = false)] 
    public int TemplateId { get; set; } 
    public string Name { get; set; } 
    public string Content { get; set; } 
} 

財產Content應該能夠接受HTML。我怎樣才能做到這一點?眼下,它拋出的錯誤:

A potentially dangerous Request.Form value was detected from the client (Content="<p>test</p>").

我知道用這個行動上的,但我不希望它適用於每個屬性:

[ValidateInput(假) ]

回答

4

而不是使用在整個模型ValidateInput屬性的,我建議你使用AllowHtml屬性上Content屬性:

public class TemplateVM 
{ 
    [HiddenInput(DisplayValue = false)] 
    public int TemplateId { get; set; } 
    public string Name { get; set; } 
    [AllowHtml] 
    public string Content { get; set; } 
} 

此屬性只適用於Content屬性,而其他屬性仍然有效。

3

[ValidateInput(false)]放在TemplateVM之上。它將適用於所有房產。