I'm new with JSON and I try to pass some data in a JsonResult method located in my controller. The method accepts an AModel as a parameter. This AModel is defined with some properties, and a BModel.
So, I wrote :
function loadDatas() {
var values =
{
"Title" : "The title",
"Text" : "Blahblahblah",
"BModel" :
{
"Summary" : "lorem ipsum",
"Page" : "15"
}
};
$.post("@Url.Action("Load", "MyController")",values,function(data)
{
// do stuff;
});
And my Load method is defined as :
[HttpPost]
public JsonResult Load(AModel test)
{
return Json(test); //dummy example, just serialize back the AModel object
}
When I put a breakpoint on Load's opening brace, test.Title and test.Text have the good values, but test.BModel.Summary and test.BModel.Page are null.
The worst part in this problem is if I put an alert(values.HousingModel.Summary); the value displayed is the good one ! Why is it not send correctly to my method whereas values.Title and values.Text are ??
I used this link to understand JSON format (http://www.sitepoint.com/javascript-json-serialization/) and mine seems valid... Isn't it ?
Thanks for your help
Alex