4

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?

1
  • I don't know the VB.NET lambda syntax but I think the second param in your TextBoxFor might be surplus - it might be interpreting that as the HTML attributes object. However that won't cause your problem here. Commented Jun 24, 2010 at 23:46

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.