Custom Data Annotation Validator Part I : Server Code
Posted by: K. Scott Allen,
on 22 Feb 2011 |
View original | Bookmarked: 0 time(s)
Let's say you want to create a GreaterThan validation attribute and use it like so: public class Trip
{
[Required]
public DateTime StartDate { get; set; }
[Required]
[GreaterThan("StartDate")]
public DateTime EndDate { get; set; }
}
The implementation would look something like this:
public class GreaterThanAttribute : ValidationAttribute
{
public GreaterThanAttribute(string otherProperty)
:base("{0} must be greater than {1}")
{
OtherProperty...