ASP.NET MVC 路由的无限 URL 参数 [英] Infinite URL Parameters for ASP.NET MVC Route
问题描述
我需要一个可以在我的 ASP.NET 控制器上获取无限参数的实现.如果我给你一个例子会更好:
I need an implementation where I can get infinite parameters on my ASP.NET Controller. It will be better if I give you an example :
假设我将有以下网址:
example.com/tag/poo/bar/poobar
example.com/tag/poo/bar/poobar/poo2/poo4
example.com/tag/poo/bar/poobar/poo89
如您所见,在 example.com/tag/
之后将获得无限数量的标签,而斜杠将作为这里的分隔符.
As you can see, it will get infinite number of tags after example.com/tag/
and slash will be a delimiter here.
在控制器上我想这样做:
On the controller I would like to do this :
foreach(string item in paramaters) {
//this is one of the url paramaters
string poo = item;
}
是否有任何已知的方法可以实现这一目标?如何从控制器获取值?用 Dictionary
或 List
?
Is there any known way to achieve this? How can I get reach the values from controller? With Dictionary<string, string>
or List<string>
?
注意:
这个问题没有很好地解释 IMO,但我尽力适应它.in. 随意调整它
The question is not well explained IMO but I tried my best to fit it. in. Feel free to tweak it
推荐答案
像这样:
routes.MapRoute("Name", "tag/{*tags}", new { controller = ..., action = ... });
ActionResult MyAction(string tags) {
foreach(string tag in tags.Split("/")) {
...
}
}
这篇关于ASP.NET MVC 路由的无限 URL 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!