I have a model that has a datetime property and I want to make sure that in the view, the form can't be submitted unless that editor for has a value.
employee { [DataType(DataType.Date)] [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)] [Required] // <- this isn't doing anything for me??? public DateTime DateOfBirth {get;set;} } is there an annotation I can use for this or do I have to use javascript in the page?
or is there another solution?
Update -
When I clear out the date editor, I get the following in my editor box:
mm/dd/yyyy when I submit this, does this count as null or what? Making the DateTime property nullable didn't fix my issue, theres no validation taking place when I submit a form that has mm/dd/yyyy for the date
DateTimeisn't going to be null. What happens if you change the type toDateTime??DateTime?is a nullableDateTime