If I have a ViewModel class that is used as a property in other ViewModel classes. It has an editor template that renders dropdowns for day, month and year, and gets and sets a date value. I want to perform validation on this ViewModel in the classes it is used, and expose its date value for validation.
This would need to work for the RequiredAttribute class etc.
I can't seem to find a way to override the property/value used for validation. I imagined there would be something like there is for WebForms validation where you can decorate the class with the 'ValidationProperty' attribute.
Something like this:
[ValidationProperty("Value")]
public class DateViewModel
{
public int Day{ get; set; }
public int Month { get; set; }
public int Year { get; set; }
public DateTime? Value { get {...} }
}
public class PersonViewModel
{
[Required(ErrorMessage = "Please specify your birth date")]
public DateViewModel BirthDate { get; set; }
}
public class AdViewModel
{
[Required(ErrorMessage = "Please specify an end date for your ad")]
[SomeCustomValidation(ErrorMessage = "The ad end date must be in the future")]
public DateViewModel EndDate { get; set; }
}