Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
public int UserID { get; set; }
    //1-CreatedBy,2 - AssignedTo, 3 - UpdatedBy
    public int UserFilterTypeID { get; set; }
    public int TaskTypeID { get; set; }
    public int TaskStatusID { get; set; }
    public HelperClass.Priority Priority{get; set; }

    // 1-DateCreated 2-DateUpdated
    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

JavaScript
$('.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
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900