Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The field 'Date' must be a date MVC 4

Im facing this error when im using my jQuery datepicker.

jQuery:

$( ".datepicker" ).datepicker({ 
    defaultDate: +7,
    autoSize: true,
    dateFormat: 'dd.mm.yy',
}); 

Model:

[DisplayName("Date")]
[DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}", ApplyFormatInEditMode = true)]
[Required(ErrorMessage = "Date is required")]
public DateTime Date { get; set; }

So I want the date format to be like dd.MM.yyyy, and when I select the date using the datepicker it is correctly added to the field. But also in the same second, an validation error appears saying The field 'Date' must be a date.

I did test with writing manually the date in the format dd/MM/yy and then it looks like it is working. So somewhere the validator looks for that format, but I cant find out where to modify it.

like image 582
Martin at Mennt Avatar asked Apr 21 '13 17:04

Martin at Mennt


1 Answers

Are you using chrome? Can be a jquery.validate.js issue, please have a look to this Jquery Datepicker Chrome

like image 181
D.Rosado Avatar answered Sep 24 '22 09:09

D.Rosado