You should specify that this is an array like this and pass each value as a parameter, but all with the same name, for example:
/?arr[]=foo+bar&arr[]=baz&arr[]=foo
Or even for some cases (like ASP MVC):
/?arr=foo+bar&arr=baz&arr=foo
As proven and on that SO-EN topic and in this post
Then in your case you should do something like this:
window.location.href = "/GAR/downloadListaGARsTratadas?GarsFiltro=1&GarsFiltro=2&GarsFiltro=3"
To generate this parameter dynamically I created this method:
function formatQueryStringURLParamArray(key, array){
var param = "";
for(var item in array){
if(param.length > 0)
param += "&";
param += key + "=" + item;
}
return param;
}
It can be called this way, returning the formatted querystring:
var param = formatQueryStringURLParamArray("key", myArray);
Here's a online example .
Example with Web API
Try the following test (I use WebApi ASP MVC, but it's very similar to MVC):
I created the following ApiController:
public class Test2Controller : ApiController
{
[HttpGet]
public virtual int Get([FromUri]int[] i)
{
return i.Length;
}
}
And I made the following request via url in my browser:
http://localhost:59402/api/test2/?i[]=1&i[]=2&i[]=3
And I correctly received the array of integers.
I do not know if MVC uses this, as it does not work with MVC WebAPi only, but try to add [FromUri]
before its array parameter in the Controller method.
Example with ASP MVC
I created this Controller:
public class Test3Controller : Controller
{
[System.Web.Http.HttpGet]
public ActionResult Index([FromUri]int[] i)
{
return Json(i, JsonRequestBehavior.AllowGet);
}
}
And I made the following request via url in my browser:
http://localhost:59402/test3/?i=1&i=2&i=3
Note: I do not know why MVC did not understand when I passed i[]
, so if I only pass i={valor}
, it understands. The Web API already worked in both ways: i={valor}
and i[]={valor}
.