0

I did make the following example, but is not working :

Controller Home:

namespace KendoUIMvcApplication1.Controllers
{
     public class HomeController : Controller
     {
          public ActionResult Index(DateTime? date)
          {
             //here i use the date bla bla bla

               return View();
          }

          public ActionResult About()
          {
               return View();
          }
     }
}

My view : Index.cshtml

<p>
    @Html.Kendo().DatePicker().Name("Calendario").Value(DateTime.Now).Events(e =>e.Change("change"))
</p>


<script type="text/javascript">
    function change() {
        var dado = this.value();
        $.ajax({
            type: "POST",
            url: "/Home/Index", //url
            traditional: false,
            async: false,
            beforeSend: function () {
            },
            data: dado,
            success: function (response) {
            },
            error: function (e) {
                alert("erro");
            }
        });
    }
</script>

Why when I change the date on the calendar, the param is null on the controller? The function $Ajax is working fine; the var dado has a date.

Jens Erat
  • 37,523
  • 16
  • 80
  • 96
lampada
  • 83
  • 2
  • 9

1 Answers1

5

Try to to send the value as Key/Value pair object. e.g.

data: {date:dado},

Also you might need to format the date into a convenient for the ModelBInder format

e.g.

data:{date:kendo.format("{0:dd/MM/yyyy hh:mm:ss tt}",dado)}
Petur Subev
  • 19,983
  • 3
  • 52
  • 68
  • Okey then the format is wrong try to send the value like I edited my answer – Petur Subev Mar 21 '13 at 19:09
  • tks again but dont work. I tried to send a simple string on data, changing the parameter on action, but dont work too. – lampada Mar 21 '13 at 21:06
  • I do not see any difference compared to the following question http://stackoverflow.com/questions/6076961/pass-date-values-from-ajax-call-to-mvc except the 'tt' part at the end of the formatting. – Petur Subev Mar 22 '13 at 07:16
  • Thank you, you are right, its worked. Works fine if you use: data: { data: kendo.toString(dado, "d") too. thank you very much @Petur-Subev – lampada Mar 22 '13 at 12:51