I am trying to write my own Custom Validation attribute, but I am having some problems.
The attribute I'm trying to write is that when a user logs in, the password will be compared with the confirmation password.
namespace Data.Attributes { public class ComparePassword : ValidationAttribute { public string PasswordToCompareWith { get; set; } public override bool IsValid(object value) { if (PasswordToCompareWith == (string)value) { return true; } return false; } }
Now my problem is that I am trying to set such an attribute in the model file:
[Required] [ComparePassword(PasswordToCompareWith=ConfirmPassword)] public string Password { get; set; } [Required] public string ConfirmPassword { get; set; } }
I get the following error:
Error 1 An object reference is required for a non-static field, method, or property 'Project.Data.Models.GebruikerRegistreerModel.ConfirmPassword.get'
It seems that VS is not accepting confirmpassword in the PasswordToCompareWith=ConfirmPassword .
What am I doing wrong?
c # validation asp.net-mvc attributes asp.net-mvc-2
user323395
source share