类属性验证简单说明

[Required(ErrorMessage ="用户名称不能为空")]--必须输入
[StringLength(50),MinLength(3)]--最大长度50最小长度3
[RegularExpression(@"")]--正则表达式
[Compare("Age")]--验证2个属性值一样
//[Remote("checkName","N")]服务端回调函数
public string Name { get; set; }


[Range(20,40)]--数字最小值和最大值
public string Age { get; set; }

[Range(typeof(decimal), "0.00", "49.99")]--- double验证
public double aaa { get; set; }

if (ModelState.IsValid)
{

}

原文地址:https://www.cnblogs.com/bug123456/p/10756028.html