2009-03-05 49 views
3

我注意到在ASP.NET MVC這樣一個有趣的一點:你如何處理可變數量的MVC路線?

routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

我想{*} PATHINFO映射到的路徑。

喜歡的東西:

routes.MapRoute(
    "area/{*pathInfo}", 
    "{controller}/{action}/{id}",parameters 
    new { controller = "Area", action = "Index", id = ??? } 
); 

,但我怎麼傳遞變量 「富/酒吧/ RAB /錢幣」 從mydomain.com/area/foo/bar/rab/oof?把整個位作爲一個字符串或者一個集合傳遞給我都可以。

謝謝!

回答

4

您正在使用哪個MVC版本?我記得在MCV Beta中,路由名稱應該是MapRoute()的第一個參數。無論如何,鑑於你捕捉路徑的目標,我會做S/T,如:

routes.MapRoute("AreaRoute", "Area/{*values}", new {controller = "Area", action = "Index"}  ); 

並在該地區控制器:

// "value" argument is the string after Area/, i.e. "foo/bar/rab/oof" in your example 
public string Index(string values) 
{ 
    ... 
} 
+0

感謝您的快速回復。我正在使用RC2。我會測試一下並回復給你。 – 2009-03-05 09:02:31