如何将 int 数组传递给 RouteValueDictionary
我需要生成此网址:http://localhost:3178/Reports/?GroupId=1211&GroupId=1237
我正在尝试:
var routeData = new RouteValueDictionary();
routeData.Add("GroupId", "1, 2");
获取:GroupId=1,%202
或
routeData.Add("GroupId", "1");
routeData.Add("GroupId", "2");
获取:已添加具有相同键的项目
,甚至
routeData.Add("GroupId[0]", "1");
routeData.Add("GroupId[1]", "2");
获取:?GroupId%5B0%5D=1&GroupId%5B1%5D=2
有可能以某种方式解决我的问题吗?
I need generate this url: http://localhost:3178/Reports/?GroupId=1211&GroupId=1237
I'm trying:
var routeData = new RouteValueDictionary();
routeData.Add("GroupId", "1, 2");
getting: GroupId=1,%202
or
routeData.Add("GroupId", "1");
routeData.Add("GroupId", "2");
getting: An item with the same key has already been added
and even
routeData.Add("GroupId[0]", "1");
routeData.Add("GroupId[1]", "2");
getting: ?GroupId%5B0%5D=1&GroupId%5B1%5D=2
it's possible to somehow fix my issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RouteValueDictionary 旨在为路由提供信息。因此,我认为它不具备您所要求的功能。我一直在使用自定义帮助程序根据我传递给它的内容填充查询字符串数据:
此函数将构建路线的完整路径并将附加参数对象中的值作为查询字符串数据附加。这可以通过执行 ToString 方法来处理数组、枚举、可为空值和其他类型。
希望这有帮助!
The RouteValueDictionary is meant to provide information to routes. As such, I don't think it has the capability you're asking for. I've been using a custom helper to populate query string data based on what I pass into it:
This function will build a full path to your route and append the values in the additionalParams object as query string data. This can handle arrays, enums, nullable values, and other types that by executing their ToString method.
Hope this helps!