I am trying to pass a nested array to an asp.net mvc controller like this:
var subgroups = [];
subgroups [0] = [["A", "Y"],
["B", "Y"],
["C", "Y"]];
subgroups [1] = [["D", "Z"],
["E", "Z"],
["F", "Z"]];
$.ajax({ url: "<%= Url.Content("~/Controller/Action") %>", data: { subgroups: subgroups },
dataType: "json", context: document.body, success: function(data) { ... } );
The resulting controller:
public ContentResult Action(List<string[][]> subgroups) {
...
}
The problem is the resulting subgroups variable in the controller looks like this:
subgroups[0][0] == null;
subgroups[0][1] == null;
subgroups[0][2] == null;
subgroups[1][0] == null;
subgroups[1][1] == null;
subgroups[1][2] == null;
The values from the deeply nested array don't get passed. Firebug reports the parameters of my ajax request are:
subgroups[0][0][] A
subgroups[0][0][] Y
subgroups[0][1][] B
subgroups[0][1][] Y
subgroups[0][2][] C
subgroups[0][2][] Y
subgroups[1][0][] D
subgroups[1][0][] Z
subgroups[1][1][] E
subgroups[1][1][] Z
subgroups[1][2][] F
subgroups[1][2][] Z
It looks like the cause is that jQuery isn't filling in these array indexes because I can fix the problem is I format the data as:
subgroups [0] = [{ 0: "A", 1: "Y"}, ...];
Why does jQuery put the indexes for the outer array, but not the inner one? Please tell me there is a better workaround for this than to manually specify numeric keys?