This is a migrated thread and some comments may be shown as answers.

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

1 Answer 823 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Wim
Top achievements
Rank 1
Wim asked on 20 Nov 2014, 11:05 AM
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
2.{
3.    public DateTime ReceiptDateTime { get; set; }
4.}

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()
4.};

How should I format the date in javascript?

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 24 Nov 2014, 09:18 AM
Hello,

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()
};
 
$.ajax({
    url: url,
    type: "POST",
    dataType: "json",
    contentType: "application/json"
    data: kendo.stringify(receipt),
    success: function() {
    },
    error: function() {
    }
});


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Date/Time Pickers
Asked by
Wim
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or