MVC 绑定回不正确的日期格式
MVC binding back incorrect date format
我正在使用 Jquery 日期选择器,如下所示:-
$(".jqueryui-marker-datepicker").datepicker({
dateFormat: "mm/dd/yy",
yearRange: "-100:+0",
changeYear: true,
changeMonth: true,
showOn: "button"
}).css("display", "inline-block").next("button").button({
icons: { primary: "ui-icon-calendar" },
label: "Select A Date",
text: false
});
以下是编辑器模板:-
@model DateTime?
@Html.TextBoxFor(model => Model,"{0:dd-MM-yyyy}",new { @class = "form-control jqueryui-marker-datepicker" });
现在我有日期时间了?我模型中的列
[Display(Name = "Date of birth")]
[DataType(DataType.Date)]
[Required(ErrorMessage = "DATEDOB is required")]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? DATEDOB { get; set; }
创建和编辑视图有以下内容
<div class=" col-md-3">
@Html.EditorFor(model => model.DATEDOB, "{0:MM/dd/yyyy}", new { htmlAttributes = new { @class = "datepicker" } })
@Html.ValidationMessageFor(model => model.DATEDOB, "", new { @class = "text-danger" })
</div>
创建日期正确进入 table
2000 年 4 月 21 日 12:00:00 上午
然而,当编辑视图出现时,它显示为
21-04-2000.
早些时候它给出了一个 jquery 验证错误,表明这不是模态日期。我已经解决了。
所以现在当我点击提交按钮时,它给我一个错误 "the value is not a valid date"
我有 "en-US" 作为文化和 Uiculture。
我目前 运行 我在印度本地机器上的网络应用程序。
我不确定如何去 about.Any 建议?
您的编辑器模板使用了不同的日期格式,请尝试更改此代码
@model DateTime?
@Html.TextBoxFor(model => Model,"{0:MM/dd/yyyy}",new { @class = "form-control jqueryui-marker-datepicker" });
我正在使用 Jquery 日期选择器,如下所示:-
$(".jqueryui-marker-datepicker").datepicker({
dateFormat: "mm/dd/yy",
yearRange: "-100:+0",
changeYear: true,
changeMonth: true,
showOn: "button"
}).css("display", "inline-block").next("button").button({
icons: { primary: "ui-icon-calendar" },
label: "Select A Date",
text: false
});
以下是编辑器模板:-
@model DateTime?
@Html.TextBoxFor(model => Model,"{0:dd-MM-yyyy}",new { @class = "form-control jqueryui-marker-datepicker" });
现在我有日期时间了?我模型中的列
[Display(Name = "Date of birth")]
[DataType(DataType.Date)]
[Required(ErrorMessage = "DATEDOB is required")]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? DATEDOB { get; set; }
创建和编辑视图有以下内容
<div class=" col-md-3">
@Html.EditorFor(model => model.DATEDOB, "{0:MM/dd/yyyy}", new { htmlAttributes = new { @class = "datepicker" } })
@Html.ValidationMessageFor(model => model.DATEDOB, "", new { @class = "text-danger" })
</div>
创建日期正确进入 table
2000 年 4 月 21 日 12:00:00 上午
然而,当编辑视图出现时,它显示为
21-04-2000.
早些时候它给出了一个 jquery 验证错误,表明这不是模态日期。我已经解决了。
所以现在当我点击提交按钮时,它给我一个错误 "the value is not a valid date"
我有 "en-US" 作为文化和 Uiculture。 我目前 运行 我在印度本地机器上的网络应用程序。
我不确定如何去 about.Any 建议?
您的编辑器模板使用了不同的日期格式,请尝试更改此代码
@model DateTime?
@Html.TextBoxFor(model => Model,"{0:MM/dd/yyyy}",new { @class = "form-control jqueryui-marker-datepicker" });