列表的验证属性< string> [英] Validation attribute for list<string>
问题描述
我收到的错误是Model.IsValid == false。
这是其中一个有错误的酒店:
// 属性
[RegularExpression( @ ^ [0-9] * $,ErrorMessage = 无效数字)]
public 列表< string>数字{获取; set ; }
// 构造函数
public ClassName()
{
Numbers = new List< string>();
}
有人可以解释一下为什么吗?我是否需要验证列表的每个元素?如何实现呢?
我尝试过:
我试图调试问题并搜索谷歌但没有找到任何有用的东西。
,ErrorMessage = 无效数字)]
public 列表< string> Numbers { get ; set ;}
// 构造函数
public ClassName()
{
Numbers = new 列表< string>();
}
有人可以解释一下为什么吗?我需要验证清单中的每个元素吗?如何实现它?
我尝试了什么:
我试图调试问题并搜索谷歌但没有找到任何有用的东西。
希望这个工作..
c# - 对我的ViewModel列表中的每个项目进行数据验证 - Stack Overflow [ ^
Hi,
I am getting an errors that Model.IsValid == false.
Here is one of the property with an error:
// Property
[RegularExpression(@"^[0-9]*$", ErrorMessage = "Invalid number")]
public List<string> Numbers { get; set; }
//Constructor
public ClassName()
{
Numbers = new List<string>();
}
Can someone explain me why? Do I need to validate each element of the List? How to achieve it?
What I have tried:
I tried to debug the problem and searched google but didn't find anything usefully.
", ErrorMessage = "Invalid number")] public List<string> Numbers { get; set; } //Constructor public ClassName() { Numbers = new List<string>(); }
Can someone explain me why? Do I need to validate each element of the List? How to achieve it?
What I have tried:
I tried to debug the problem and searched google but didn't find anything usefully.
Hope this works..
c# - Data validation for every item in a list of my ViewModel - Stack Overflow[^]
这篇关于列表的验证属性< string>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!