c# - Html.HiddenFor在ASP.NET中错误地格式化DateTime

我正在用C_编写一个ASP.NET MVC3应用程序,并且发现如果我要调用Html.HiddenFor的话,在我的视图中调用DateTime会使Html.DisplayFor呈现出不同(并且不正确)的效果。
它从中获取值的模型确实有一个DisplayFormat修饰符,这似乎适用于Html.DisplayFor。有关财产写为:

[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime MeetingStartDate { get; set; }

视图将使用以下方式显示:
 @Html.DisplayFor(model => model.MeetingStartDate)
 @Html.HiddenFor(model => model.MeetingStartDate)

displayfor调用会将日期呈现为16/04/2012,但是hiddenfo会将日期呈现为value="04/16/2012 00:00:00"
我试过改变当前的文化设置一个DateTimeFormat但是没有效果。
目前的文化是en-gb,所以它不应该在美国打印日期。


最佳答案:

如果指定日期格式和HTML隐藏属性,则使用textbox for的视图内替代项将起作用。

@Html.TextBoxFor(model => model.CreatedDate, "{0:dd/MM/yyyy HH:mm:ss.fff}", htmlAttributes: new { @type = "hidden" })