I want to validate a textbox to accept datetime value using DataAnnotations in MVC3. But I don't have any idea how to do it. Given below is what I'm trying to accomplish my requirement and it's not working.
[DataType(DataType.DateTime, ErrorMessage = "Invalid Datetime")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy HH:mm}")]
[Display(Name = "Start Datetime")]
public DateTime? StartDateTime { get; set; }
As When I click on submit button after filling corrupted data first problem is that form get post and later it shows the message that "Invalid date" and second if I enter just date without time still form get post but this time it does not shows the message which is also wrong.
So I just want to know how can I validate my textbox to accept datetime in "dd/MM/yyyy HH:mm" format only using MVC DataAnnotations .
datetimepicker
? – Nitin Varpe