Passing nested arrays to asp.net mvc using jQuery's $.ajax

前端 未结 2 1087
臣服心动
臣服心动 2021-01-23 09:14

I am trying to pass a nested array to an asp.net mvc controller like this:

var subgroups = [];
subgroups [0] = [[\"A\", \"Y\"],
                 [\"B\", \"Y\"],
         


        
相关标签:
2条回答
  • 2021-01-23 09:54

    in file "code.jquery.com/jquery-1.4.2.js" in line 5290:

    buildParams( prefix + "[" + ( typeof v === "object" jQuery.isArray(v) ? i : "" ) + "]", v );
    

    I change for this code:

    buildParams(prefix + (typeof v === "object" jQuery.isArray(v) ? "[" + i + "]" : ""), v);
    

    and the result was good. I could not test on many more cases.

    I create a ticket in jQuery.com to see if this is a bug: Ticket #6900 (new bug)

    but in:

    public ContentResult Action(List<string[][]> subgroups) {
    

    for this modification, you have to use this code:

    public ContentResult Action(List<string[]> subgroups) {
    
    0 讨论(0)
  • 2021-01-23 09:58

    In case anyone else stumbles on this question like I did but doesn't like the idea of modifying jQuery to work with your particular server software, I ended up using JSON.stringify() to pass a JSON string of nested arrays to the server, and then decoding that JSON string on the server.

    0 讨论(0)
提交回复
热议问题