Is there any way to know which validation attribute caused ModelState.IsValid == false
.
Class A
public class A
{
[Required(ErrorMessage = "Required")]
[DataFormat(DataType.Date, "Must be a Date (DD/MM/YEAR)")]
[NoFutureDate(ErrorMessage = "Future date is not allowed")]
public DateTime? Date { get; set; }
}
Now when I post the form which have the above mentioned class strongly typed with it's view, then validation attributes will work accordingly.
What if 1 of the 3 validation attributes return an error, say [NoFutureDate(ErrorMessage = "Future date is not allowed")]
.
OR
What if 2 of the 3 validation attributes return an error, say [NoFutureDate(ErrorMessage = "Future date is not allowed")]
and [DataFormat(DataType.Date, "Must be a Date (DD/MM/YEAR)")]
.
Surely my property failed the validations.
Question
Is there a way to know which validation attribute caused the error?
Is it the [DataFormat]
one or both [DataFormat]
and [NoFutureDate]
.