简体   繁体   中英

Pass array using ajax into controller

Here is the code: where arg is [1,2,3]

function filtersearch(arg) {
        var arry = [];
        arry = arg;
    debugger
        $.ajax(
        {
            type: "POST",
            url: '@Url.Action("getFilterActiveData")',
            dataType: "json",
            data: { args: arry },
            tradition: true,
            async: true,
            success: function (data) {
            debugger
                side_menu(data.listdata.length, data.listdata, data.color);
            }
        });

Array value is not passed in controller

  public ActionResult getFilterActiveData(string[] args){}

shows null in args..any suggestion?

Try validate that the arg values are in the correct format and what data gets posted to the action method.

When I test with filtersearch([1,2,3]) it binds the result correctly.

One correction: The parameter tradition should be traditional http://api.jquery.com/jquery.ajax/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM