问题描述:

I've been using Data Annotations Extensions for a while now. I want to use the EqualTo attribute but ran into an null reference exception.

Here is the model:

 [Required(ErrorMessage = "Password is required.")]

public string Password { get; set; }

[Required(ErrorMessage = "Please confirm your password.")]

[EqualTo("Password",ErrorMessage="Your passwords do not match.")]

public string PasswordConfirm { get; set; }

If I remove the EqualTo attribute the post is successful, but with the EqualTo I get a null reference exception. Can anyone suggest a reason why?

网友答案:

Use CompareAttribute: [Compare("Password", ErrorMessage = "Your passwords do not match.")]

相关阅读:
Top