DateTime format when sending with JSON to ASP.NET Web Api controller

2 posts, 0 answers
  1. Wim
    Wim avatar
    16 posts
    Member since:
    Oct 2014

    Posted 20 Nov 2014 Link to this post

    I have a DateTimePicker in my view, binding to my model's DateTime field, like this:

    1.@Html.Kendo().DateTimePickerFor(m => m.ReceiptDateTime);

    With this ViewModel: (I've omitted the irrelevant fields)

    1.public class ReceiptViewModel
    3.    public DateTime ReceiptDateTime { get; set; }

    Now, I'm trying to post this to a WebAPI controller in ASP.NET Web API using JSON. I've tried many ways, but the controller never receives the value for the DateTime and sets it at a default "{1-1-0001 0:00:00}". How can I send the date to the controller?

    1.var receipt = {
    2.    /* more fields here */
    3.    ReceiptDateTime: $("#ReceiptDateTime").data("kendoDateTimePicker").value()

    How should I format the date in javascript?
  2. Daniel
    Daniel avatar
    2177 posts

    Posted 24 Nov 2014 Link to this post


    If you wish to post the data as JSON then you should use similar configuration to the one in the snippet below:
    var receipt = {
        ReceiptDateTime: $("#ReceiptDateTime").data("kendoDateTimePicker").value()
        url: url,
        type: "POST",
        dataType: "json",
        contentType: "application/json"
        data: kendo.stringify(receipt),
        success: function() {
        error: function() {

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top