How do you link to an action that takes an array as a parameter (RedirectToAction and/or ActionLink)
Posted
by Andrew
on Stack Overflow
See other posts from Stack Overflow
or by Andrew
Published on 2010-03-15T22:27:08Z
Indexed on
2010/03/15
22:29 UTC
Read the original article
Hit count: 352
I have an action defined like so:
public ActionResult Foo(int[] bar) { ... }
Url's like this will work as expected:
.../Controller/Foo?bar=1&bar=3&bar=5
I have another action that does some work and then redirects to the Foo
action above for some computed values of bar
.
Is there a simple way of specifying the route values with RedirectToAction or ActionLink so that the url's get generated like the above example?
These don't seem to work:
return RedirectToAction("Foo", new { bar = new[] { 1, 3, 5 } });
return RedirectToAction("Foo", new[] { 1, 3, 5 });
<%= Html.ActionLink("Foo", "Foo", new { bar = new[] { 1, 3, 5 } }) %>
<%= Html.ActionLink("Foo", "Foo", new[] { 1, 3, 5 }) %>
However, for a single item in the array, these do work:
return RedirectToAction("Foo", new { bar = 1 });
<%= Html.ActionLink("Foo", "Foo", new { bar = 1 }) %>
When setting bar to an array, it redirects to the following:
.../Controller/Foo?a=System.Int32[]
Finally, this is with ASP.NET MVC 2 RC.
Thanks.
© Stack Overflow or respective owner