【问题标题】:Invalid Date from DatePicker [duplicate]DatePicker 中的无效日期 [重复]
【发布时间】:2017-05-17 14:03:23
【问题描述】:

在我的 C# MVC 程序中使用 jQuery DatePicker 函数,但它给了我一个错误,要么是“无效日期”,要么是我今天的默认日期“17/05/2017”无效。

这是我的 jQuery 以及 Create.cshtml 中的标签/编辑器:

<div class="editor-label">
        @Html.LabelFor(model => model.DateOfReading)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.DateOfReading)
        @Html.ValidationMessageFor(model => model.DateOfReading)
    </div>

 <script>
if (datefield.type!="date"){ //if browser doesn't support input type="date", initialize date picker widget:
    jQuery(function ($) { //on document.ready


        $('#DateOfReading').datepicker({ dateFormat: 'dd/mm/yy', maxDate: 0, defaultDate: 0 }).val(new Date().toLocaleDateString());
    })
}
</script>

这是我的实体:

 [Required(ErrorMessage = "You must input a date")]
    [Display(Name = "Date of Meter Reading")]
    [DataType(DataType.Date)]
    public DateTime DateOfReading { get; set; }

【问题讨论】:

    标签: c# jquery asp.net-mvc


    【解决方案1】:

    将此属性添加到您的方法中。

    [DisplayFormat(DataFormatString = "{0:dd/MM/yy}", ApplyFormatInEditMode = true)]
    

    【讨论】:

    • 我收到消息“值 '‎17‎/‎05‎/‎2017' 对于抄表日期无效。”还是那个
    • 我认为 [Display(Name = "Date of Meter Reading")] 也应该是 [Display(Name = "DateOfReading")]。
    • jquery 插件提供了什么价值?如果可以的话,在其中放置一个 console.log。
    • 嘿,我对 jQuery 很陌生,但是我应该把 console.log 放在哪里?
    • 是的,我看到了重复的帖子答案。认为沿着这条路线走你可能会有更好的运气。抱歉,我无法为您解决这个问题。
    猜你喜欢
    • 1970-01-01
    • 2019-04-29
    • 2019-02-11
    • 2020-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多