【发布时间】:2021-01-29 19:25:38
【问题描述】:
有没有办法让 ASP MVC 5 将所有类型视为应用了范围最小值和最大值?
也就是说,这样就不必将范围属性添加到每个可能的属性中?
[Range(0, int.MaxValue, ErrorMessage = "Value beyond accepted range")]
public int? Thing{ get; set; }
[Range(0, int.MaxValue, ErrorMessage = "Value beyond accepted range")]
public int? AnotherThing { get; set; }
并且在属性具有指定范围属性的地方使用该属性(覆盖默认行为)?
为每个属性添加范围验证器非常重复和乏味,并且会破坏 DRY。
我认为它可能在每个属性类型的编辑器模板中完成?
【问题讨论】:
标签: c# asp.net-mvc