Datepicker value to controller not matching

3 posts, 0 answers
  1. Joachim
    Joachim avatar
    7 posts
    Member since:
    Oct 2014

    Posted 11 May 2015 Link to this post

    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.

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

  2. Joachim
    Joachim avatar
    7 posts
    Member since:
    Oct 2014

    Posted 12 May 2015 Link to this post

    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.




  3. Daniel
    Daniel avatar
    2177 posts

    Posted 13 May 2015 Link to this post


    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.

    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
Back to Top