你如何处理可变数量的MVC路线?

时间:2022-06-09 04:50:44

I note this intriguing bit in ASP.NET MVC:

我注意到ASP.NET MVC中这个有趣的部分:

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

I'd like to map {*pathInfo} into a route.

我想将{* pathInfo}映射到路线中。

Something like:

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

but how do I pass in the variable "foo/bar/rab/oof" from mydomain.com/area/foo/bar/rab/oof? Either passing the entire bit as a string or as a collection would be fine with me.

但如何从mydomain.com/area/foo/bar/rab/oof传入变量“foo / bar / rab / oof”?将整个位作为字符串或集合传递都可以。

Thanks!

1 个解决方案

#1


Which MVC version are you using? The route name should be the first parameter to MapRoute() as I remember in MCV Beta. Anyway, given your goal of capturing the path, I would do s/t like:

您使用的是哪个MVC版本?路径名应该是MapRoute()的第一个参数,就像我在MCV Beta中记得的那样。无论如何,考虑到你捕捉路径的目标,我会不喜欢:

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

And in the Area controller:

在区域控制器中:

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

#1


Which MVC version are you using? The route name should be the first parameter to MapRoute() as I remember in MCV Beta. Anyway, given your goal of capturing the path, I would do s/t like:

您使用的是哪个MVC版本?路径名应该是MapRoute()的第一个参数,就像我在MCV Beta中记得的那样。无论如何,考虑到你捕捉路径的目标,我会不喜欢:

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

And in the Area controller:

在区域控制器中:

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