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

Datepicker value to controller not matching

2 Answers 831 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Joachim
Top achievements
Rank 1
Joachim asked on 11 May 2015, 02:16 PM

Hi guys,

I've setup a datepicker, it's showing the selected date properly but I'm having a hard time in sending it towards my controller in the same format it's showing. For some reason it seems to be reverting back from dd/MM/yyyy to MM/dd/yyyy.

Below my script used.

01.<script>
02.    var datepicker;
03.    $(document).ready(function () {
04.        datepicker = $("#datepicker").data("kendoDatePicker");
05. 
06.        $("#btnToReport").click(function () {
07.            $.post("/ShiftReport/ViewReport?datepicker=" + datepicker.value().toLocaleString(), function (data, status) {
08.                if (status === "success") {
09.                    $("#main-content").html(data);
10. 
11.                }
12.            });
13.        });
14.    });
15.</script>

2 Answers, 1 is accepted

Sort by
0
Joachim
Top achievements
Rank 1
answered on 12 May 2015, 09:27 AM

Slap on forehead,

I had setup my controller to accept a DateTime parameter. I changed this to accept a string (makes more sense) this allowed me to just parse the string into a DateTime in the format I needed to continue working with it.

1.var mainDate = DateTime.ParseExact(requestedDate, "dd/MM/yyyy HH:mm:ss",null);

Still if someone would have a solution to still send in a DateTime towards the controller straight away in the format I'm looking for, always nice to see how that would be done.

 

 

 

0
Daniel
Telerik team
answered on 13 May 2015, 09:52 AM
Hi,

The default model binder uses the invariant culture formats to parse the value when it is sent in the query string. So in order for the value to be bound, you should either format the query string value in the expected format:
"/ShiftReport/ViewReport?datepicker=" + kendo.toString(datepicker.value(), "MM/dd/yyyy")
or implement a custom model binder for the DateTime type that parses the values based on the needed format.

Regards,
Daniel
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Date/Time Pickers
Asked by
Joachim
Top achievements
Rank 1
Answers by
Joachim
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or