【发布时间】:2017-04-13 10:56:38
【问题描述】:
我正在使用以下代码在我的剃刀视图中弹出 日期 的日历
型号
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
[DataType(DataType.Date)]
public Nullable<System.DateTime> EndTime { get; set; }
查看
<div class="form-group">
@Html.LabelFor(model => model.EndTime, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-4">
@Html.EditorFor(model => model.EndTime, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.EndTime, "", new { @class = "text-danger" })
</div>
</div>
现在我想使用 DateTime 而不是 Date。DataFormat 字符串应该是什么?
我的尝试
Display(Name = "End Date Time")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}{1:HH/mm}")]
[DataType(DataType.DateTime)]
我收到格式异常?
【问题讨论】:
-
您是否尝试过简单的 DataFormatString = "{0:dd/MM/yyyy HH:mm}")]?
-
是的,我确实使用过,但在这种情况下,日历根本不会弹出。
-
你用什么来显示日历?那是引导程序吗?
-
我写了查看代码也请看。
-
如果你想要 HTML-5 日期时间选择器,那么你需要使用
@Html.TextBoxFor(m => m.EndTime, "{0:s}", new { @type = "datetime-local", @class = "form-control" })。但请注意,它仅在最新版本的 Chrome 和 Edge 中受支持
标签: c# asp.net-mvc format-string