用Ajax调用操作方法

I tried the solution below without success. In the controller method MvcAction, the prs parameter is always null. Below is the code I'm using to call the controller method.

function getPerson() {
    var jFirstName = '@Model.Person.FirstName';
    var jLastName = '@Model.Person.LastName';
    return { FirstName: jFirstName, LastName: jLastName };
}

var person = getPerson();
var jsonPerson = JSON.stringify(person);

$.post( '@Url.Action("MvcAction", "MvcXontroller")', { prs : jsonPerson },
function( data ) {
    ....
});

The action method look like this:

public void MvcAction(Person prs)
{

}

Is data null or are you getting 404 errors because the routing engine can not find the MvcAction method?

My guess is that since your return type is void, the result will always be null. Change your return type to JsonResult or something like it if you want to return data back to the client.

UPDATE

Try updating your $.post() call like this:

$.post( '@Url.Action("MvcAction", "MvcXontroller")', JSON.stringify({ prs : person}),
    function( data ) {
        ....
    });

Also verify before the $.post call that person is a valid jason object with values in First and Last name.