I have this attribute in my view model:
[DataType(DataType.DateTime)]
public DateTime? StartDate { get; set; }
If I want to display the dat
Use this, but it's a complete solution:
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
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
Use EditorFor rather than TextBoxFor
That works for me
[DataType(DataType.DateTime)]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]