本文介绍了AllowHtml不适用于Array的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET MVC项目中使用AllowHtml属性,但是它不适用于我的视图模型中的数组.如果该属性不是数组,则该属性有效.现在,我无法验证我的html标签.

I use the AllowHtml attribute in my ASP.NET MVC project but it doesn't work with an array in my view model. If the property isn't an array the attribute works. And now, I can't validate my html tags.

有什么建议吗?谢谢

[AllowHtml]

public string[] ContentText { get; set; }

错误:

A potentially dangerous Request.Form value was detected from the client

推荐答案

它不适用于数组. 它必须是一个简单的字符串属性,才能正常工作 .你能做的就是

It will not work with arrays . It must be a simple string property for this to work. What you can do is

public class ContentText { [AllowHtml]public string Text { get; set; } }

然后让您的主模型将此ContentText的集合作为属性:

and then have you main model take a collection of this ContentText as property:

public class ContentTextCollection { public ContentText [] Texts { get; set; } }

这篇关于AllowHtml不适用于Array的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 10:58