I have a JavaScript function where I pass 4 arrays, each of these is of the type
[1, 2] with only int values inside or [] with no values inside. these are passed into an Url.Action
command.
function Filter(locations, machines, severities, messages) {
var url = '@Url.Action("Filter", "ActiveMessages")?' + $.param({
locations: locations, machines: machines, severities: severities, messages: messages });
$.ajax({
url: url,
method: 'POST',
traditional: true,
success: function (data) { }
});
}
I tried to build the parameters using $.param()
. but this doesn't generate the parameters i'm expecting, I get something like this: "/ActiveMessages/Filter?locations%5B%5D=1"
I also tried doing this:
decodeURIComponent($.param({ locations: filterlocations, machines: filtermachines, severities: filterseverities, messages: filtermessages }))
Then I get something like this:
"/ActiveMessages/Filter?locations[]=1&locations[]=2"
Are there any other ways to parse such an array into an url?
Receiving happens in the controller:
public async Task<ActionResult> Filter(int[] locations, int[] machines, int[] severities, int[] messages)
{
//TODO filter
}
This gets called but the parameters are null;
when I started out I used this which works for a single value but needs to be extended to an array.
var url = '@Url.Action("Filter", "ActiveMessages")' + '?locations=' + locations + '&machines=' + machines + '&severities=' + severities + '&messages=' + messages;