asp.net mvc 验证
1、使用tryUpdatemodel 的方式
2、在model中加入 类似以下代码
[DisplayName("First Name"), StringLength(50)]
public string FirstName { get; set; }
[DisplayName("Middle Name"), StringLength(50)]
public string MiddleName { get; set; }
[DisplayName("Last Name"), StringLength(50), Required]
public string LastName { get; set; }
[DisplayName("Birth Date"), DataType(DataType.Date)]
public DateTime BirthDate { get; set; }
[DataType(DataType.EmailAddress), Required]
public string Email { get; set; }
public string Phone { get; set; }
public string Postcode { get; set; }
[DataType(DataType.MultilineText)]
[DisplayName("Middle Name"), StringLength(50)]
public string MiddleName { get; set; }
[DisplayName("Last Name"), StringLength(50), Required]
public string LastName { get; set; }
[DisplayName("Birth Date"), DataType(DataType.Date)]
public DateTime BirthDate { get; set; }
[DataType(DataType.EmailAddress), Required]
public string Email { get; set; }
public string Phone { get; set; }
public string Postcode { get; set; }
[DataType(DataType.MultilineText)]
public string Notes { get; set; }
3、客户端验证
需要在模板里面加入 :<% Html.EnableClientValidation(); %>