Passing array parameters from jquery to ASP.NET MVC

Does anyone have any idea what is going on here? Here is my jQuery 1.4.1 code of my clients:

$.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 signature:

public ActionResult Print(int[] ids)

The ids parameter is always null.

Any ideas?

By the way, I am doing this at the top of the page:

 jQuery.ajaxSettings.traditional = true

UPDATE: see comments in Stephen below for permission.

+3
source share
2 answers

try the following:

changes:

data: [1, 2, 3],

to

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

You need to do:

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

Source: https://habr.com/ru/post/1731892/


All Articles