我有一个这样定义的动作:
public ActionResult Foo(int[] bar) { ... }
Run Code Online (Sandbox Code Playgroud)
像这样的网址将按预期工作:
.../Controller/Foo?bar=1&bar=3&bar=5
Run Code Online (Sandbox Code Playgroud)
我有另一个动作可以做一些工作,然后重定向到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 }) %>
Run Code Online (Sandbox Code Playgroud)
但是,对于数组中的单个项目,这些确实有效:
return RedirectToAction("Foo", new { bar = 1 });
<%= Html.ActionLink("Foo", "Foo", …Run Code Online (Sandbox Code Playgroud) asp.net-mvc url-routing redirecttoaction actionlink asp.net-mvc-routing