I am using ASP.NET MVC 4 and I am trying to send a JSON object to a controller that accepts
Here is my javascript and jQuery:
var jsonObject = {
"PlantShipTo":{
"PlantID" : shipToID.toString()
}
};
$.ajax({
type: "POST",
contentType: 'application/json; charset=utf-8',
timeout: 15000,
url: "/Transfer/TransferOut",
data: JSON.stringify(jsonObject),
dataType: 'json',
tradational: 'true',
success: function (response) {
}
});
In my controller I am accepting an object of type "PlantShipTo" defined below:
public class PlantShipTo
{
public int PlantID { get; set; }
}
For brevity, I will only show the controller definition:
public ActionResult TransferOut(PlantShipTo shipto)
{
PlantShipTo p = shipto;
I expect the MVC model binding to recognize the JSON as a PlantShipTo object, but the object is null when I check it in the controller. Below is some of my request info courtesy of Fiddler. The JSON looks like it matches my "PlantShipTo" class. What am I missing ?
Accept: application/json, text/javascript, */*; q=0.01
Content-Type: application/json; charset=utf-8
X-Requested-With: XMLHttpRequest
{"PlantShipTo":{"PlantID":"2"}}