0

我有以下路线:

   routes.MapRoute(
      name: "One",
      url: "admin/{id}",
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
   );
   routes.MapRoute(
      name: "Two",
      url: "home/{id}",
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
   );

有没有一种方法可以将这些路由组合成一个路由,它们都指向“Home”控制器?

4

1 回答 1

1

尝试

 routes.MapRoute(
           name: "Default2",
           url: "{section}/{id}",
           defaults: new {section="home" ,controller = "Home", action = "Index", id = UrlParameter.Optional }
       );

为我工作

回答评论。添加约束有什么问题?

 routes.MapRoute(
           name: "Default2",
           url: "{section}/{id}",
           defaults: new { section = "home", controller = "Home", action = "Index", id = UrlParameter.Optional },
           constraints: new { section = "admin|home" }
       );
于 2013-06-14T12:35:36.443 回答