【发布时间】:2018-03-28 23:58:22
【问题描述】:
我有一个包含出生日期字段的 MVC6 编辑视图,如下所示:
<div class="form-group">
@Html.LabelFor(model => model.DateOfBirth, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@*@Html.EditorFor(model => model.DateOfBirth, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.DateOfBirth, "", new { @class = "text-danger" })*@
@Html.EditorFor(m => m.DateOfBirth,new { htmlAttributes = new { @readonly = "readonly" } })
@Html.ValidationMessageFor(model => model.DateOfBirth, "", new { @class = "text-danger" })
</div>
</div>
因此,当我单击“保存”时,错误提示:“07/17/1981”值对 ApplicationDate 无效。如何确保日期以英国格式显示,这意味着验证成功。
我在 Bubdle.Config 中添加了以下答案:
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/globalize.js",
"~/Scripts/jquery.validate.globalize.js"));
【问题讨论】:
-
您是在客户端还是在服务器端收到此错误?
-
“我已尝试将此添加到 en-gb 到”... 到什么?
-
请阅读How to Ask 并分享您的研究。许多现有问题都涉及到这个确切的问题。
-
@Codecaster,该字段是只读的(如代码所示)。您的链接建议使用 DatePicker 并没有帮助。
-
@Scrobi,我知道仅显示会解决它。我只是很感兴趣。
标签: c# asp.net asp.net-mvc