Assign format of DateTime with data annotations? Assign format of DateTime with data annotations? asp.net asp.net

Assign format of DateTime with data annotations?


Try tagging it with:

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]


Did you try this?

[DataType(DataType.Date)]


In mvc 4 you can easily do it like following using TextBoxFor..

@Html.TextBoxFor(m => m.StartDate, "{0:MM/dd/yyyy}", new { @class = "form-control default-date-picker" })

So, you don't need to use any data annotation in model or view model class