当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net mvc - mvc2 data annotations extensions EqualTo

问题描述:

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.")]

分享给朋友:
您可能感兴趣的文章:
随机阅读: