780 questions
Write custom validation.
public class OrderHistoryRequestDto : IValidatableObject
{
[Required(ErrorMessage = "Please add StartDate to the request.")]
[DataType(DataType.Date)]
public DateTime? StartDate { get; set; }
[Required(ErrorMessage = "Please add EndDate to the request.")]
[DataType(DataType.Date)]
public DateTime? EndDate { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if(EndDate.Value <= StartDate.Value)
{
yield return new ValidationResult("End date must be greater than the start date.", new[] { "EndDate" });
}
}
}
If you want an attribute then write a custom attribute.
There is also the openly published documentation which you can read to figure out if an existing attribute will suit your needs. For example, the compare attribute.