ASP MVC: Custom Validation Attribute
Posted
by user323395
on Stack Overflow
See other posts from Stack Overflow
or by user323395
Published on 2010-04-27T11:34:32Z
Indexed on
2010/04/27
11:43 UTC
Read the original article
Hit count: 325
I'm trying to write my own Custom Validation attribute but i'm having some problems.
The attribute i'm trying to write is that when a user logs in, the password will be compared against the confirmation password.
namespace EventCompanion.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 when i'm trying to set the attribute like this 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 the non-static field, method, or property 'Project.Data.Models.GebruikerRegistreerModel.ConfirmPassword.get'
It seems that VS is not accepting the confirmpassword in the "PasswordToCompareWith=ConfirmPassword" part
Now my question:
What am i doing wrong?
Thanks in advance!!!
© Stack Overflow or respective owner