ASP.Net Html.TextBoxFor日期时间参数的格式不起作用

时间:2016-07-25 02:55:47

标签: c# asp.net

cshtml中的代码:

@Html.LabelFor(m => m.StartDateTime, new { @class = "lbl100" })
                    @Html.TextBoxFor(m => m.StartDateTime, "{0:yyyy-MM-dd}", new { @class = "form-control control120" })
                    @Html.LabelFor(m => m.EndDateTime, new { @class = "lbl100" })
                    @Html.TextBoxFor(m => m.EndDateTime, "{0:yyyy-MM-dd}", new { @class = "form-control control120" })

有两种方法可以从Ajax.Actionlink菜单中获取此操作 并形成pagedlist actionlink

这是价值表格菜单: enter image description here

这是页面列表的价值形式: enter image description here

为什么格式参数不起作用?

1 个答案:

答案 0 :(得分:0)

如果String.Format内的TextBoxFor内的DisplayFormat无法正常工作,请在DateTime模型属性上使用[DisplayName("Start Date")] [DataType(DataType.Date)] // if HTML5 is used you can apply this attribute [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")] public DateTime StartDateTime { get; set; } [DisplayName("End Date")] [DataType(DataType.Date)] // if HTML5 is used you can apply this attribute [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")] public DateTime EndDateTime { get; set; } 放置格式样式以强制执行日期输入。

php.ini

有用的参考:Date only from TextBoxFor()