视图运行正常,我可以看到datetimepicker,但是当我单击提交时,datetime字段为null(如果可以为空)或01/01/0001 00:00(如果不能为空)。
查看
<div class="form-group">
@Html.LabelFor(model => model.LaycanStartDate, htmlAttributes: new { @class = "control-label col-md-12" })
<div class="col-md-10">
@Html.EditorFor(model => model.LaycanStartDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.LaycanStartDate, "", new { @class = "text-danger" })
</div>
</div>
<script>
$(function () {
$.validator.methods.date = function (value, element) {
var date = moment(value, "DD/MM/YYYY HH:mm", true).format("DD/MM/YYYY HH:mm");
return this.optional(element) || moment(date, "DD/MM/YYYY HH:mm", true).isValid();
}
});
</script>
型号
[Display(Name = "LaycanStartDate", ResourceType = typeof(Resources.Resources))]
[DataType(DataType.DateTime)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy HH:mm}")]
public DateTime LaycanStartDate { get; set; }
DateTime.cshtml
@model DateTime?
@(Html.Kendo().DateTimePickerFor(m => m).HtmlAttributes(new { style = "width: 100%; max-width: 280px", title = "datetimepicker"}))
答案 0 :(得分:0)
所以我最终能够解决这个问题的唯一方法是删除控制器上的绑定[Bind(....
如果没有允许值通过且控制器可以处理格式