Crystal
Crystal

Reputation: 29518

Internal Server Error when trying to post jquery date to controller

I'm just getting started with asp.net mvc3. I have a jquery date picker that I want to pass the value and call an update method in my controller with the date selected. So in my details.cshtml view, I have this:

$(document).ready(function () {
        $('#ImplementationStart').datepicker({
            onSelect: function (date) {
                $.ajax({
                    url: '/request/update/',
                    type: 'POST',
                    data: {
                        Date: date
                    },
                    contentType: 'application/json; charset=utf-8',
                       success: function (date) {
                        alert(date);
                    },
                    error: function(xhr, textStatus, error){
                    console.log(xhr.statusText);
                    console.log(textStatus);
                    console.log(error);
                    }                           
                });
            }
        });
    });

In my RequestController, I have this code:

public ActionResult Update(Request request)
    {
        Console.WriteLine("hi");

        return View();
    }

It currently does not do anything, but it doesn't get to this method and I'm wondering what I'm doing wrong. When I look at the Console on IE9, it just says,

LOG: Internal Server Error 
LOG: error 
LOG: Internal Server Error

Any thoughts on what I am doing wrong? Thanks!

Upvotes: 0

Views: 225

Answers (1)

Kirill Bestemyanov
Kirill Bestemyanov

Reputation: 11964

You post to controller variable with name Date and type DateTime, but your controller takes variable of type Request. Chenge signature of action method:

public ActionResult Update(DateTime date)
{...}

and it will work.

Upvotes: 1

Related Questions