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

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

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

类似的东西:

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

但是如何传入变量“foo / bar / rab / oof”?来自mydomain.com/area/foo/bar/rab/oof?将整个位作为字符串或集合传递对我来说没问题。

谢谢!

有帮助吗?

解决方案

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

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)  
{  
  ...
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top