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?

Sivaraman DhamodaranRank #40 · 34.5K reputationPosted Apr 14, 2014, 2:41 AM EDT
Are you looking for something else?
If (Name==Password)
{
//Validation Failed
}
else
{
//Passed
}
Sasi ReddyRank #4,458 · 342 reputationPosted Apr 14, 2014, 2:46 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 14, 2014, 2:52 AM EDT
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 ReddyRank #4,458 · 342 reputationPosted Apr 14, 2014, 3:11 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 14, 2014, 3:42 AM EDT
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.