列表的验证属性< string>

编程入门 行业动态 更新时间:2024-10-21 14:19:28
本文介绍了列表的验证属性< 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[^]

更多推荐

列表的验证属性&lt; string&gt;

本文发布于:2023-11-02 17:30:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552981.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   列表   amp   gt   string

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!