Yar*_*icx 2 c# asp.net-mvc attributes
我在ASP.NET MVC项目中使用AllowHtml属性,但不适用于视图模型中的数组。如果该属性不是数组,则该属性有效。现在,我无法验证我的html标签。
有什么建议吗?谢谢
[AllowHtml]
public string[] ContentText { get; set; }
Run Code Online (Sandbox Code Playgroud)
错误:
A potentially dangerous Request.Form value was detected from the client
Run Code Online (Sandbox Code Playgroud)
它不适用于数组。它必须是一个简单的字符串属性才能起作用。你能做的是
public class ContentText { [AllowHtml]public string Text { get; set; } }
Run Code Online (Sandbox Code Playgroud)
然后让您的主模型将此集合ContentText作为属性:
public class ContentTextCollection { public ContentText [] Texts { get; set; } }
Run Code Online (Sandbox Code Playgroud)