1

路线信息

routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
       new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
        // Parameter defaults
            );

routes.MapRoute(
        "Default1", // Route name
        "{controller}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

网址信息

http://localhost:24060/home/22323      //Failed
http://localhost:24060/home/index/22323    //Passed\

查询,我怎样才能同时传递两个网址?

4

1 回答 1

1

您必须最后映射默认路线。此外,您应该在其他路由中创建一个约束,以不阻止默认路由。

routes.MapRoute(
        "Default1",
        "{controller}/{id}",
        new { controller = "Home", action = "Index", id = UrlParameter.Optional },
        new { id = @"\d+" });
        //second segment has to be an integer, otherwise skip this route.

routes.MapRoute(
        "Default",
        "{controller}/{action}/{id}",
       new { controller = "Home", action = "Index", id = UrlParameter.Optional });
于 2013-05-21T19:03:04.373 回答