For now, I've settled for submitting a flat list via javascript, which is then built out on the server side.
The javascript:
var parents = [];
parents.push(new Parent("asdf", "qwer"));
parents.push(new Parent("zxcv", 123456));
[4,5,].forEach(function (e, i) {
params.push(new Parent("Children[" + i + "]", e));
});
Which looks like this after JSON.stringify
:
[{"Name":"asdf","Value":"qwer"},{"Name":"zxcv","Value":123456},{"Name":"Children[0]","Value":4},{"Name":"Children[1]","Value":5},{"Name":"Children[2]","Value":6}]
And is then un-flattened in the Controller via the following function:
private IEnumerable<Parent> Unzip(IEnumerable<Parent> parameters) {
var unzipped = new Dictionary<string, Parent>();
var r = new Regex(@"(.*)\[.*\]");
foreach (var p in parameters)
{
var match = r.Match(p.Name.ToString());
if (match.Success)
{
var name = match.Groups[1].Value;
if (!unzipped.ContainsKey(name))
unzipped.Add(name, new Parent() { Name = name, Value = new List<object>() { } });
((List<object>)(unzipped[name].Value)).Add(p.Value);
}
else
unzipped.Add(p.Name, p);
}
return unzipped.Values;
}