多值GET参数 - 路线生成 [英] Multi-value GET parameters - route generation

查看:88
本文介绍了多值GET参数 - 路线生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用多值的GET参数,像这样:

When using multi-value GET parameters like so:

/?param=1&param=2&param=3

您可以自动模式绑定到一个列表,像这样:

You can automatically model-bind to a list, like so:

public ActionResult MyAction(List<int> param)

我如何可以通过使用匿名类型这样的值,在URL生成?

How can I pass such values using anonymous types, in URL generation?

@Url.Action("MyAction", new { param = ?? })

使用数组/列表的工作 -

@Url.Action("MyAction", new { param = new List<string>{ "1", "2", "3" } })

由于它只是吐出了 Object.ToString()这样的:

?param=System.Collections.Generic.List%601%5BSystem.String%5D

干杯

推荐答案

不是很好的解决方案后,你,买你能做到的,假设你知道是否添加?还是不行。

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("&param=", new [] {1, 2, 3})

也许一个帮手可以写的做到这一点。看到 URL.Action一个字符串数组?

这篇关于多值GET参数 - 路线生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆