how to fix 'The field must be a date' on a datetime property in mvc

前端 未结 13 1122
逝去的感伤
逝去的感伤 2020-12-29 06:59

I need to capture date and time both for my model property. In my model class I have the following

[Required]
[DataType(DataType.DateTime)]
public DateTime?          


        
13条回答
  •  [愿得一人]
    2020-12-29 07:28

    I added the fix for date format parser, but I needed to set the format to 'L' so it could be work in all Locales:

    $(function () {
    $.validator.methods.date = function (value, element) {
        return this.optional(element) || moment(value, "L", true).isValid();
    }
    });
    

提交回复
热议问题