views:

58

answers:

1

I've got my display format setup as so

<DisplayName("birthdate")> _
<DisplayFormat(ApplyFormatInEditMode:=True, DataFormatString:="{0:MM/dd/yyyy}")> _
Public Property BirthDate As DateTime

Then in the View I have the following

<%: Html.TextBoxFor(Function(model) model.BirthDate, Model.BirthDate)%>
<%: Html.ValidationMessageFor(Function(model) model.BirthDate) %>

Meaning that the output "should" be

6/24/1982

But unfortunately, the output is

6/24/1982 12:00:00 AM

Does anyone know what I might be missing here?

+3  A: 

Digging through the MVC2 source from Codeplex, my best guess is that you need to use EditorFor not TextBoxFor. TextBoxFor uses

string valueParameter = Convert.ToString(value, CultureInfo.CurrentCulture);

ignoring the format attributes (although it did look them up through the ModelMetadata classes) whereas EditorFor and DisplayFor are built on the internal TemplateHelpers which do use the format attributes.

Rup
EditorFor worked. Thanks
rockinthesixstring