The RequiredAttribute
works for string
but not DateTime
. For example:
[Required]
[DisplayFormat(ConvertEmptyStringToNull = false)]
public string Name { get; set; }
[Required]
[DataType(DataType.DateTime)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd-MMM-yyyy}", ConvertEmptyStringToNull = false)]
public DateTime Birthdate { get; set; }
If Name
is empty the Validation shows error, but if Birthdate
is empty then nothing happens. I looked at:
ASP MVC 5 Client Validation for Range of Datetimes
and
but still doesn't work for the DateTime