开发者

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 resol开发者_如何学运维ution.


try the following:

change:

data: [1, 2, 3],

to

data: {"ids": [1, 2, 3]},


You need to do:

data: { "ids[0]": 1, "ids[1]": 2, "ids[2]": 3},
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜