Why doesnt 3 level nesting model binding from json work?
Testing with 2 levels, say adding a string property on LevelTwo, works, but 3 levels doesnt? Is this by design, a bug, or am I missing something?
Client side jQuery post:
$.ajax({
url: "MyController/MyAction",
dataType: "json",
type: "POST",
cache: false,
data: {
Level1: {
Level2: {
StringValue: "Test"
}
}
}
});
Server side model:
public class MyForm
{
public LevelOne Level1 { get; set; }
}
public class LevelOne
{
public LevelTwo Level2 { get; set; }
}
public class LevelTwo
{
public string StringValue { get; set; }
}
You are not sending any JSON to the server. If you want to send a JSON request here’s how:
The
JSON.stringifymethod is what serializes the javascript literal into a JSON string. It is natively built in modern browsers. If you need to support legacy browsers you could include the json2.js script to your page.