I am having a problem displaying / editing a date in MVC 3.
I set the property of my data class as follows (the data is actually provided by the Linq2Sql object):
[DisplayName("Date of Birth")] [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}", NullDisplayText = "")] public DateTime DoB { get; set; }
In the view, I then:
@Html.TextBoxFor(m => m.DoB, new { @class = "date" })
The problem is that the text field always shows the time part of the date, for example. '18 / 10/2010 00:00:00 '
I know I can overcome this problem using the standard Html.TextBox
@Html.TextBox("DoB", Model.DoB.ToShortDateString())
but I really want to be able to control this from a data model.
I found articles on the Internet that show that this works, but I cannot repeat their success.
Any help / advice would be appreciated.
source share