添加更多路由到asp.net MVC Global.asax

时间:2011-09-13 01:53:58

标签: asp.net asp.net-mvc

我有一条地图路线,如:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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



    }

但我想添加更多路线网址,我该怎么做?

1 个答案:

答案 0 :(得分:9)

只需添加其他MapRoute()

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

routes.MapRoute(
    "SecondRoute",
    "{controller}/{action}/{tags}",
    new { controller = "Products", action = "Index", tags = "" }
);

我建议您通过The Gu进行路由this excellent post