When using multi-value GET parameters like so:
当使用多值时,得到如下参数:
/?param=1¶m=2¶m=3
You can automatically model-bind to a list, like so:
您可以自动将模型绑定到列表,如下所示:
public ActionResult MyAction(List<int> param)
How can I pass such values using anonymous types, in URL generation?
如何在URL生成中使用匿名类型传递这些值?
@Url.Action("MyAction", new { param = ?? })
Using an array / list doesn't work -
使用数组/列表不工作-
@Url.Action("MyAction", new { param = new List<string>{ "1", "2", "3" } })
As it just spits out Object.ToString()
like:
因为它刚刚吐出Object.ToString() like:
?param=System.Collections.Generic.List%601%5BSystem.String%5D
Cheers
干杯
1 个解决方案
#1
1
Not the nice solution your after, buy you could do, assuming you know whether to add the ? or not.
如果你知道是否要添加的话,买你能做的,不是一个好的解决方案。与否。
@Url.Action("MyAction")?param=@string.Join("¶m=", new [] {1, 2, 3})
Maybe a helper could be written that does this. see URL.Action with a string array?
也许可以写一个助手来做这个。看到URL。使用字符串数组操作?
#1
1
Not the nice solution your after, buy you could do, assuming you know whether to add the ? or not.
如果你知道是否要添加的话,买你能做的,不是一个好的解决方案。与否。
@Url.Action("MyAction")?param=@string.Join("¶m=", new [] {1, 2, 3})
Maybe a helper could be written that does this. see URL.Action with a string array?
也许可以写一个助手来做这个。看到URL。使用字符串数组操作?