我想验证文本框中的输入,使其为整数,范围为0-255。我有一个小的asp.net mvc4项目
答案 0 :(得分:2)
使用数据注释:http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-6
[Required(ErrorMessage = "Value must be set")]
[Range(0, 250, ErrorMessage = "Value must be between 0 and 250")]
public int Value{ get; set; }
答案 1 :(得分:2)
对于任何整数,请使用以下方法:
[Required(ErrorMessage = "Value must be set")]
[Range(0, int.MaxValue, ErrorMessage = "Value must be between 0 and 250")]
public int Value{ get; set; `enter code here`}