public partial class NormalRegistration
{
[Required]
public string Name { get; set; }
[Required]
public string Password { get; set; }
}
This is my model class.I need to compare both name and password but both should not be equal.For that how to write the validation for that?..
please tell me how to write validation?
Jignesh TrivediPosted Apr 14, 2014, 7:42 AM
In this case, you have to write custom validation attribute
Please refer my article
http://www.c-sharpcorner.com/UploadFile/ff2f08/creating-custom-validation-attribute-for-data-annotation/
hope this will help you.
Sasi ReddyPosted Apr 14, 2014, 7:11 AM
Jignesh TrivediPosted Apr 14, 2014, 6:52 AM
Hi,
I think, Using compare attribute you can achive this
[Compare("Name", ErrorMessage = "The Name and password do not match.")]
public string Password { get; set; }
hope this will help you.
Sasi ReddyPosted Apr 14, 2014, 6:46 AM
Sivaraman DhamodaranPosted Apr 14, 2014, 6:41 AM
Are you looking for something else?
If (Name==Password)
{
//Validation Failed
}
else
{
//Passed
}