Search code examples
jqueryasp.netasp.net-mvc-4kendo-uikendo-asp.net-mvc

Kendo Datepicker converting to jQuery post a date value


In javascript I get the date from my kendo datetime

var myDate = $("#mydate").getKendoDatePicker().value();

(Looks like this) Fri May 29 2015 00:00:00 GMT-0700 (Pacific Daylight Time)

Then I try to post it to ASP.NET MVC using jQuery:

    $.ajax({

        type: "POST",

        url: "/HeaderData",

        data: myDate,

        success: successHeaderData,

        dataType: 'json'

    });

But the date is not parsed by the Action in MVC.

How do I convert the "Fri May 29 2015 00:00:00 GMT-0700 (Pacific Daylight Time)" into a date that ASP.NET MVC will accept?


Solution

  • Add the method .toJSON() to convert to an ISO format date

    var myDate = $("#mydate").getKendoDatePicker().value().toJSON();
    

    outputs "2015-05-30T06:41:32.576Z"