Possible Duplicate:
Post an Array of Objects via JSON to ASP.Net MVC3
I'm trying to post a JSON object to an MVC3 controller. I seen solutions for this in stackoverflow, but most of the solutions are where the JSON object is then binded to a model. How do I make so that the post JSON object (array) is convert to an array of generic c# Object types? Or something that allows me to loop through the json objects. Please keep in mind the object is never the same. I basically want to create one controller that will allow me to loop the json object and the get the data from there. Currently right now I get an array of objects in the MVC controller, but then I can't seem to see the data in them. Any ideas?
Don't know if I'm going down the right path.
Thank you, -Tesh
Javascript:
var parm = JSON.stringify({ session_id: sessionId, data: data, metaData: metaData })
var ret = "";
$.ajax({
type: 'post',
cache: false,
url: path + "/Common/Export/Load",
data: parm,
dataType: "json",
contentType: "application/json; charset=utf-8",
traditional: true,
async: false,
success: function (data) {
//ret = data.Table[0].Column1;
},
error: function (event, request, settings) {
//alert('save error: ' + JSON.stringify(request)) + ', ' + JSON.stringify(settings);
}
});
MVC Controller
[HttpPost]
public ActionResult Load(String session_id, List<object> data, Object metaData)
{
return View();
}
JSON Object Passed to Controller. The object can at any time.
{
"Table": [ { "first_name": John, "last_name": Doe, "creation_date": "2012-10-04T15:50:37.55", "created_by": Mary Jane, "last_modified_date": "2012-10-04T15:50:37.55", "last_modified_by": Jon Mitchell
},
{
"first_name": Bill,
"last_name": Doe,
"creation_date": "2012-10-04T15:50:37.55",
"created_by": Jane Wick,
"last_modified_date": "2012-10-04T15:50:37.55",
"last_modified_by": Jon Mitchell
}
] }