I want to create a custom validation attribute, in which I want to compare the value of my property with another property's value in my model class. For example I have in my model class:
...
public string SourceCity { get; set; }
public string DestinationCity { get; set; }
And I want to create a custom attribute to use it like this:
[Custom("SourceCity", ErrorMessage = "the source and destination should not be equal")]
public string DestinationCity { get; set; }
//this wil lcompare SourceCity with DestinationCity
How can I get there?
Here's how you could obtain the other property value:
Please look below for my example:
Model class implements
INotifyPropertyChanged
Attribute class also contains event hendler.
Usage
To simplify code I decided to omit a validation.
The best way to do this, is through of IValidatableObject. See http://msdn.microsoft.com/en-us/data/gg193959.aspx