且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用具有相同名称的多个值的RouteValues

更新时间:2023-02-23 22:24:57

您可以通过以下方式进行操作:

You can do it in the following way:

string url = Url.Action("DoFilter", TypeHelper2.ObjectToDictionary(filter) );

TypeHelper2.ObjectToDictionary 是.NET内部方法的修改版本,可以在此

The TypeHelper2.ObjectToDictionary is a modified version of an internal method of .NET, and can be found in this two file gist.

已更改的行为:当一个项目实现 IEnumerable 时,对于每个项目,都会有一个条目在返回的字典中使用键"Name [index]" 创建索引(索引从0开始).这是可能的,因为MVC控制器的绑定程序可以处理 tag = 1& tag = 3 tag [0] = 1& tag [1] = 3 查询字符串

Changed behavior: when an item implements IEnumerable, for each item an entry is created in the returned dictionary with as key "Name[index]" (the index is 0 based). This is possible because the binder of the MVC controller can handle both tag=1&tag=3 and tag[0]=1&tag[1]=3 query strings.