I'm currently trying to post a JSON object from my view to my controller in an MVC 3 app and I'm expecting the data from the request to bind to the model parameter of my controller action. However, when I inspect the HTTP POST request, it looks like the data is being passed as a query string and I'm unsure why (pretty new to all this).
Here's my POST request:
$.ajax({
type: 'POST',
url: "Test/Add",
data: { Name: name, Age: age },
success: function (data) {
console.log("success");
},
error: function (xhr, data, message) {
console.log(data + ": " + message);
},
dataType: "json"
});
Here's the code from my Controller followed by the code for the model I'm trying to bind to:
[HttpPost]
public ActionResult Add(PersonModel person)
{
System.Threading.Thread.Sleep(1000);
return View();
}
// person model:
public class Person {
public string Name {get;set;}
public int Age {get;set;}
}
This is the request from fiddler - I've highlighted the parts I'm unsure about:

I thought content type would be "application/json" and that the data wouldn't look like a query string - I thought it would look something like this:
{
Name: "James",
Age: 13
}
Ultimately the problem is that if I stick a breakpoint in my controller action I expect to see a populated Person object but it's always null. If I replace the signature to be something like (object name, object age) then I get values for the parameters (a string array for both - so name is a string array with 1 element which is equal to "James").
Any ideas where I've gone wrong?
Oh and just FYI, I'm not actually 13! Those were the first numbers I mashed.
Thanks!
James