Tuesday, December 4, 2012

Passing Multidimensional Array through Ajax to Controller


In view pge Create a Ajax call  and set the property Tradition:true 


1) the call will be like

    $.ajax({
                url: "controller/Action",
                type: "POST",
                traditional: true,
                contentType: 'application/json',
                data: JSON.stringify({outerLayer :[["a","b","c"],["d","r","g"]]}),
                dataType: 'json'
            }).done(function () {
                alert("sucess");
            });

2) In the controller the action method should like

    [httpPost]
    public ActionResult SaveFlow(string[][] outerLayer )

 now automatically the value will be there in outerlayer we can iterate through the string and get the needed data


For passing normal array though the ajax and binding to the model in mvc you can visit this link.
http://www.ienablemuch.com/2011/05/pass-array-from-jquery-to-aspnet-mvc.html?showComment=1354648913792#c691247510822739097