DatePickder change evnt send to controller

4 posts, 0 answers
  1. Maurice
    Maurice avatar
    13 posts
    Member since:
    Jan 2016

    Posted 27 Sep Link to this post

    Hi,

    I have a view with a standalone datepicker (controller/index(DateTime? date))

    @(Html.Kendo().DatePicker()
          .Name("datePicker")
          .Events(e => e.Change("change"))
          )

    Now I want to have a change event to go to the same page (controller/index(date = result of the datepicker)

    function change() {
    //something
    }

  2. Eduardo Serra
    Admin
    Eduardo Serra avatar
    50 posts

    Posted 27 Sep Link to this post

    Hello Maurice,

    You can implement an ajax call inside the change function and send this.value to the controller like this:

    01.function change() {
    02.        var date = this.value();
    03. 
    04.        var action = '@Url.Action("yourAction", "yourController")';
    05.        var url = kendo.format("{0}/{1}",
    06.            action,
    07.            date);
    08. 
    09.        $.ajax({
    10.            url: url,
    11.            success: function (Address) {
    12.               ...your custom success logic
    13.        });
    14.    }

    I hope this helps!

    Regards,
    Eduardo Serra
    Telerik by Progress
    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Maurice
    Maurice avatar
    13 posts
    Member since:
    Jan 2016

    Posted 28 Sep in reply to Eduardo Serra Link to this post

    This does work but the url will become

    url = "/controller/action/Thu Sep 01 2016 00:00:00 GMT+0200 (W. Europe Daylight Time)"

    Which isn't a nice url.

    I hope to insert the date into

    public ActionResult Index(DateTime? startDate)

    Is this possible?

     

    Maurice

     

     

    public ActionResult Index(DateTime? startDate)

  5. Eduardo Serra
    Admin
    Eduardo Serra avatar
    50 posts

    Posted 28 Sep Link to this post

    Hello Maurice,

    Kendo UI is capable of manipulating date objects for situations such as these; I encourage you to take a look at our Date Formatting guide and choose a format that works for you and can be passed to the controller in a more elegant way.

    I hope this helps!

    Regards,
    Eduardo Serra
    Telerik by Progress
    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
UI for ASP.NET MVC is VS 2017 Ready