ASP.NET MVC 路由的无限 URL 参数 [英] Infinite URL Parameters for ASP.NET MVC Route

查看:35
本文介绍了ASP.NET MVC 路由的无限 URL 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个可以在我的 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;

}

是否有任何已知的方法可以实现这一目标?如何从控制器获取值?用 DictionaryList?

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屋!

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