Asp.net

ASP.NET MVC 路由的無限 URL 參數

  • September 22, 2011

我需要一個可以在我的 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(string item in paramaters) { 

   //this is one of the url paramaters
   string poo = item;

}

有什麼已知的方法可以實現這一目標嗎?如何從控制器中獲取值?與Dictionary<string, string>List<string>

筆記 :

這個問題沒有很好地解釋海事組織,但我盡我所能去適應它。隨意調整它

像這樣:

routes.MapRoute("Name", "tag/{*tags}", new { controller = ..., action = ... });

ActionResult MyAction(string tags) {
   foreach(string tag in tags.Split("/")) {
       ...
   }
}

引用自:https://stackoverflow.com/questions/7515644