2009-03-05 46 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