Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing array parameters from jquery to ASP.NET MVC

Does anyone have any insight on what's going on here? Here is my clientside jquery 1.4.1 code:

$.ajax({
    type: "POST",
    url: "PrintBOL/Print",
    data: [1, 2, 3],
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    error: function(xmlHttpRequest, status, errorThrown) {
        console.debug(xmlHttpRequest)
    },
    success: function(serverReply) {
        console.debug("OK")
        console.debug(serverReply)
    }
})

Here is my server-side method signature:

public ActionResult Print(int[] ids)

The ids parameter always comes across as null.

Any ideas?

By the way I make sure I invoke this at the top of the page:

 jQuery.ajaxSettings.traditional = true

UPDATE: See comments in Steven's answer below for resolution.

like image 244
George Mauer Avatar asked Dec 12 '25 00:12

George Mauer


1 Answers

try the following:

change:

data: [1, 2, 3],

to

data: {"ids": [1, 2, 3]},
like image 58
Steven Pardo Avatar answered Dec 13 '25 13:12

Steven Pardo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!