I am writing an ASP.NET MVC3 application in C # and found that calling Html.HiddenFor
in my view would display DateTime
differently (and incorrectly) if I were to call Html.DisplayFor
.
The model in which it takes a value has a DisplayFormat decorator, and this seems to work for Html.DisplayFor
. The corresponding property is written as:
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)] public DateTime MeetingStartDate { get; set; }
And the view displays this using:
@Html.DisplayFor(model => model.MeetingStartDate) @Html.HiddenFor(model => model.MeetingStartDate)
Calling DisplayFor will display the date as 16/04/2012
, however HiddenFor will display it as value="04/16/2012 00:00:00"
.
I tried changing the current culture to set DateTimeFormat
, but that did not affect.
The current culture is en-GB, so it should not print dates in the USA in any case.
source share