I have a datePicker on my site, and i use the value to send via Ajax request to my ActionResult which takes in a viewModel seen:
public int UserID { get; set; }
public int UserFilterTypeID { get; set; }
public int TaskTypeID { get; set; }
public int TaskStatusID { get; set; }
public HelperClass.Priority Priority{get; set; }
public int DateTypeID { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime DateFrom { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime DateTo { get; set; }
the datepicker is set up like this
$('.datepicker').datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
regional: "en-GB"
});
when the ajax parameters are inspected dateFrom shows 18/12/2014 (18th Dec 2014), but when inspect the values from the viewModel on the actionResult dateFrom shows 01/01/0001 00:00:000 (default date) as if it can't parse the date because its expecting US Format, but i've set displayFormat to dd/mm/yyyy in the ViewModel and set the datepicker settings to dd/mm/yy so should be in GB regional settings.
I use modernizr to recognise if browser supports date types, and this is why it works in Chrome using their own datepicker, but in FireFox and IE using datepicker, the wrong date gets passed to viewModel, (but is in the correct format in the data params of ajax request)
please help people