DataAnnotation用于检查整数是否为负值

joh*_* Gu 2 asp.net-mvc asp.net-mvc-4

Quantity在SQL Server 2008的表中有一列.但我想在我的asp.net mvc web应用程序中编写一个数据注释,检查输入的值是否大于或等于1?那么有谁能告诉我使用哪种数据注释?

谢谢

avs*_*099 6

这有用吗?

[Range(1, Int32.MaxValue, ErrorMessage = "Value should be greater than or equal to 1")]
Run Code Online (Sandbox Code Playgroud)