【发布时间】:2011-08-31 12:12:13
【问题描述】:
在 asp.net mvc 中使用属性进行验证非常好。到目前为止,我一直在使用 [Range(min, max)] 验证器来检查值,例如:
[Range(1, 10)]
public int SomeNumber { get; set; }
但是 - 现在我需要分别检查最小和最大条件。我希望找到这样的属性:
[MinValue(1, "Value must be at least 1")]
[MaxValue(10, "Value can't be more than 10")]
public int SomeNumber { get; set; }
是否有任何预定义的属性来编写这个?或者我如何实现这一目标?
【问题讨论】:
-
FluentValidation 可以是解决日期范围的另一种解决方案。 Here is my answer to another question that might be helpful.