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

前端 未结 13 1203
逝去的感伤
逝去的感伤 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:29

    1. Install moment.js (Install-Package Moment.js)
    2. Open jquery.validate.js and find the method date: function (value, element)
    3. Replace the content for this:

      var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
      return this.optional(element) || (isChrome ? moment(value, 'L').isValid() : !/Invalid|NaN/.test(new Date(value)));
      
    4. Done

提交回复
热议问题