ASP.NET MVC Display Format Does Not Format DateTime for Date String Only
I have set the display format setting
<DisplayName("birthdate")> _ <DisplayFormat(ApplyFormatInEditMode:=True, DataFormatString:="{0:MM/dd/yyyy}")> _ Public Property BirthDate As DateTime Then in view I have the following
<%: Html.TextBoxFor(Function(model) model.BirthDate, Model.BirthDate)%> <%: Html.ValidationMessageFor(Function(model) model.BirthDate) %> The value that should be "must"
6/24/1982
But unfortunately, the conclusion
6/24/1982 12:00:00 AM
Does anyone know what I'm missing here?
Digging through Codeplex's MVC2 source, I suppose you need to use EditorFor not TextBoxFor . TextBoxFor uses
string valueParameter = Convert.ToString(value, CultureInfo.CurrentCulture); ignoring format attributes (although they looked through them through ModelMetadata classes), while EditorFor and DisplayFor are built on internal TemplateHelpers that use format attributes.