In previous versions of ASP.NET MVC the way to add custom validation to your model was by implementing the IValidatableObject and implementing your own Validate() method.
Here's what I have implemented:
public class BestModelEver: IValidatableObject
{
public DateTime? Birthday { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (Birthday.HasValue)
{
yield return new ValidationResult("Error message goes here");
}
}
}
Is this still the recommended way of adding custom validation to a model in ASP.NET Core? Using IValidatableObject takes on a System.ComponentModel.DataAnnotations dependency.