ASP.NET MVC的路线无限URL参数 [英] Infinite URL Parameters for ASP.NET MVC Route
问题描述
我需要一个实现,我可以在我的ASP.NET控制器获得无限的参数。这将是更好,如果我给你举个例子:
让我们假设我将有以下网址:
example.com/tag/poo/bar/poobar
example.com/tag/poo/bar/poobar/poo2/poo4
example.com/tag/poo/bar/poobar/poo89
正如你所看到的,它会在 example.com/tag /
获得的标记无限数量和斜线将在这里的分隔符。
在控制器我想做到这一点:
的foreach(在PARAMATERS字符串项){ //这是URL PARAMATERS之一
字符串便便=项目;}
有任何已知的方式来实现这一目标?我怎样才能从控制器到达值?随着词典<字符串,字符串>
或列表<串>
注意:
问题是没有得到很好的解释IMO但我尽我所能,以适应它。
英寸随意调整它
块引用>解决方案这样的:
routes.MapRoute(名,标签/ {*}标签,新{控制器= ...,行动= ...});的ActionResult MyAction(字符串变量){
的foreach(在tags.Split字符串标记(/)){
...
}
}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 :
Let's assume that I will have following urls :
example.com/tag/poo/bar/poobar example.com/tag/poo/bar/poobar/poo2/poo4 example.com/tag/poo/bar/poobar/poo89
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; }
Is there any known way to achieve this? How can I get reach the values from controller? With
Dictionary<string, string>
orList<string>
?NOTE :
The question is not well explained IMO but I tried my best to fit it. in. Feel free to tweak it
解决方案Like this:
routes.MapRoute("Name", "tag/{*tags}", new { controller = ..., action = ... }); ActionResult MyAction(string tags) { foreach(string tag in tags.Split("/")) { ... } }
这篇关于ASP.NET MVC的路线无限URL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!