简体   繁体   English

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

[英]Kendo dateTimePickerFor sending NULL or 01/01/0001 00:00 to controller

The view is working correctly and I can see the datetimepicker but when I click submit the datetime fields are null (if nullable) or 01/01/0001 00:00 if not nullable. 视图工作正常,我可以看到datetimepicker但是当我单击提交时,datetime字段为空(如果可为空)或01/01/0001 00:00如果不可为空。

View 视图

<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>

Model 模型

[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 DateTime.cshtml

@model DateTime? 
@(Html.Kendo().DateTimePickerFor(m => m).HtmlAttributes(new { style = "width: 100%; max-width: 280px", title = "datetimepicker"}))

So the only way I was eventually able to get around this was to remove the binding on the controller [Bind(.... 因此,我最终能够解决这个问题的唯一方法是删除控制器上的绑定[Bind(....

Without that it allows the value through and the controller can deal with the format 没有它,它允许值通过,控制器可以处理格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 日期时间“0001-01-01T00:00:00”的问题 - Problem with the DateTime "0001-01-01T00:00:00" 将可为空的 DateTime 字段更新为 null 会导致默认 DateTime 值 (0001-01-01 00:00:00.0000000) - Updating a nullable DateTime field as null results in default DateTime value (0001-01-01 00:00:00.0000000) 提交的日期时间转换为“0001-01-01T00:00:00” - Submitted datetime is converted to "0001-01-01T00:00:00" C#DateTime默认值Issue 01/01/0001 00:00:00 - C# DateTime Default Value Issue 01/01/0001 00:00:00 解析时间跨度 1:00 和 01:00 - Parse TimeSpan 1:00 and 01:00 在TextBox中显示01/01/1999而不是01/01/1999 00:00:00 - Display 01/01/1999 instead of 01/01/1999 00:00:00 in TextBox ASP.Net API DateTime ISO8601 日期值在生产中被解析为默认日期 (01/01/0001 00:00:00) &amp; Azure - ASP.Net API DateTime ISO8601 date value being parsed as default date (01/01/0001 00:00:00) in production & Azure C# 二进制数组“{ 84, 01, 00, 00 }” 在 Windows 注册表中更改为“54 01 00 00” - C# Binary Array “{ 84, 01, 00, 00 }” changed to “54 01 00 00” in Windows Registry MySQL“空”日期是否有值(0001-01-01) - Is there a value for MySQL “null” date (0001-01-01) 该操作未在指定的00:01:00超时内完成 - The operation did not complete within the allotted timeout of 00:01:00
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM