我有一个这样定义的动作:
public ActionResult Foo(int[] bar) { ... }
像这样的 URL 将按预期工作:
.../Controller/Foo?bar=1&bar=3&bar=5
我有另一个动作,它做了一些工作,然后重定向到Foo
上面的动作以获取bar
.
是否有一种简单的方法可以使用 RedirectToAction 或 ActionLink 指定路由值,以便像上面的示例一样生成 url?
这些似乎不起作用:
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 }) %>
但是,对于数组中的单个项目,这些确实有效:
return RedirectToAction("Foo", new { bar = 1 });
<%= Html.ActionLink("Foo", "Foo", new { bar = 1 }) %>
将 bar 设置为数组时,它会重定向到以下内容:
.../Controller/Foo?bar=System.Int32[]
最后,这是 ASP.NET MVC 2 RC。
谢谢。