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

[Solved] DatePicker Value in Ajax Post

2 Answers 199 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Cyndie
Top achievements
Rank 1
Cyndie asked on 27 Sep 2010, 08:03 PM
If I use the following in a client-side function with a date 1/1/2010 selected, the alert box says the value is
Fri Jan 1 00:00:00 EST 2010

var selectedMinDate = $('#MinDate').data('tDatePicker').value();
            alert(selectedMinDate);

I get a 'dateTimeFormat' is null or not an object if I attempt an $.Ajax post of the value to a DateTime variable.  How can I convert a DatePicker value to the a standard DateTime format like {0:d}?

I tested my Ajax POST by putting "1/1/2010" in place of the DatePicker value and it works, so it doesn't appear to see the value of DatePicker as a DateTime.

Thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 28 Sep 2010, 08:33 AM
Hi Cyndie,

 The value of the datepicker is a JavaScript Date object. The value which you see alerted is the string representation of the JavaScript date (date.toString()) which unfortunately the MVC model binder does not recognize as a valid date. The good news is that there is a JavaScript function which you can use to format the date as .NET string:

var value = datepicker.value();
var valueAsString = $.telerik.formatString('{0:d}', value);


Then you can pass that string to $.ajax

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Cyndie
Top achievements
Rank 1
answered on 28 Sep 2010, 01:49 PM
Perfect, thanks!
Tags
Date/Time Pickers
Asked by
Cyndie
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Cyndie
Top achievements
Rank 1
Share this question
or