在asp.net mvc中使用EditorFor和DateTime

时间:2012-08-05 20:57:09

标签: asp.net asp.net-mvc-3 asp.net-mvc-4

我在Html.EditorFor()字段中使用DateTime方法。但是我遇到了一个错误,比如年,月和日参数描述了一个无法表示的DateTime。

然后我明白这是因为月值大于12或小时值大于23.我选择了正确的值,但我认为由于本地化问题,它会在月和日之间改变位置。

还有一些代码;

从观点来看;

 <tr>
    <td>
        <div class="editor-label" style="text-align: right;">
            <b>@Html.LabelFor(c => c.Created)</b>
        </div>
    </td>
    <td>
        <div class="editor-field">
            @Html.EditorFor(c=>c.Created)
            @Html.ValidationMessageFor(c => c.Created)
        </div>
    </td>
</tr>

来自视图模型方面;

        [Display(Name = "Created", ResourceType = typeof(ModelLocalization))]
        public DateTime Created { get; set; }

我该如何格式化?我该怎么办?

1 个答案:

答案 0 :(得分:0)

您可以使用(免费)Telerik MVC扩展的TimePicker控件。 See here用于演示和here (for example) for download

注意:MVC扩展最近被新产品取代,MVC扩展的维护将stop soon