Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing nested arrays to asp.net mvc using jQuery's $.ajax
    primarykey
    data
    text
    <p>I am trying to pass a nested array to an asp.net mvc controller like this:</p> <pre><code>var subgroups = []; subgroups [0] = [["A", "Y"], ["B", "Y"], ["C", "Y"]]; subgroups [1] = [["D", "Z"], ["E", "Z"], ["F", "Z"]]; $.ajax({ url: "&lt;%= Url.Content("~/Controller/Action") %&gt;", data: { subgroups: subgroups }, dataType: "json", context: document.body, success: function(data) { ... } ); </code></pre> <p>The resulting controller:</p> <pre><code>public ContentResult Action(List&lt;string[][]&gt; subgroups) { ... } </code></pre> <p>The problem is the resulting subgroups variable in the controller looks like this:</p> <pre><code>subgroups[0][0] == null; subgroups[0][1] == null; subgroups[0][2] == null; subgroups[1][0] == null; subgroups[1][1] == null; subgroups[1][2] == null; </code></pre> <p>The values from the deeply nested array don't get passed. Firebug reports the parameters of my ajax request are:</p> <pre><code>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 </code></pre> <p>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:</p> <pre><code>subgroups [0] = [{ 0: "A", 1: "Y"}, ...]; </code></pre> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload