Passing Date from View to Controller.

2 posts, 0 answers
  1. Lavakesh
    Lavakesh avatar
    1 posts
    Member since:
    Sep 2015

    Posted 09 Sep 2015 Link to this post

    The problem is I'm not able to pass the date selected by user from Kendo Date time picker in View to Controller using ajax call. Any help or input would be much appreciated. When I put the debugger, I found that control is just passing over it but not hitting the  Action method in the Home controller.




    <div class="chart-wrapper">
            .Title("Power Output")
            .Legend(legend => legend
            .ChartArea(chartArea => chartArea
            .SeriesDefaults(seriesDefaults =>
                seriesDefaults.Area().Line(line => line.Style(ChartAreaStyle.Smooth))
            .Series(series =>
            .CategoryAxis(axis => axis
            .ValueAxis(axis => axis
                .Labels(labels => labels.Format("{0}"))
                .Line(line => line.Visible(false))
            .Tooltip(tooltip => tooltip
                .Template("#= #: #= value #")
        <h4>Select Date</h4>
        <input id="datepicker"/>
            $(document).ready(function() {
                function onChange() {
                    var date = kendo.toString(this.value());
                    $.post('/Home/Index', { "date": date }, function () {
                        alert("data is posted successfully");
                    open: onChange,
                    value: new Date()





    using Newtonsoft.Json;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Web;
    using System.Web.Mvc;
    using SparklineChart.Models;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    using Newtonsoft.Json.Linq;

    namespace SparklineChart.Controllers
        public class HomeController : Controller
            private static Class1[] _download_serialized_json_data<ActualPower>(string url) where ActualPower : new()
                //This is to temporarily to disable the SSL Certificate check.
                ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
                { return true; };

                using (var w = new WebClient())
                    var json_data = string.Empty;
                        json_data = w.DownloadString(url);
                    catch (Exception ) { }
                    return !string.IsNullOrEmpty(json_data) ? JsonConvert.DeserializeObject<Class1[]>(json_data) : new Class1[] { };


            public ActionResult Index()

                var url = "";
                var actualPower = _download_serialized_json_data<ActualPower>(url);
                Dictionary<DateTime, decimal> power = new Dictionary<DateTime, decimal>();
                List<decimal> value = new List<decimal>();
                List<DateTime> timeStamp = new List<DateTime>();
                foreach (var item in actualPower)
                    power.Add(Convert.ToDateTime(item.timeStamp.localTimeStamp), Convert.ToDecimal(item.deviceData.value));
                ViewBag.Power = power;
                ViewBag.Value = value;
                ViewBag.TimeStamp = timeStamp;
                return View();

            public String Index(DateTime date)
                if (date != null)
                return "Success";
                return "Failure";
                //return Content(Convert.ToString(date));

            public ActionResult About()
                return View();


  2. Georgi Krustev
    Georgi Krustev avatar
    3724 posts

    Posted 12 Sep 2015 Link to this post

    Hello Lavakesh,

    As the ticket is related to DatePicker widget, I will update the forum product section.

    With regards to the question, I would suggest you the following StackOverflow topic that discusses how to send JavaScript Date object to the server: Please note that this question is not related to UI for ASP.NET MVC by any means, but rather is general ASP.NET MVC knowledge.

    Georgi Krustev
    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