Kendo dateTimePicker用于向控制器发送NULL或01/01/0001 00:00

问题描述 投票:0回答:1

视图工作正常,我可以看到datetimepicker但是当我单击提交时,datetime字段为空(如果可为空)或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"}))
c# asp.net-mvc datetimepicker kendo-asp.net-mvc
1个回答
0
投票

因此,我最终能够解决这个问题的唯一方法是删除控制器上的绑定[Bind(....

没有它,它允许值通过,控制器可以处理格式

© www.soinside.com 2019 - 2024. All rights reserved.