在mvc 4中的routeconfig.cs中设置自定义路径

时间:2013-05-30 12:13:51

标签: asp.net-mvc-4 routing asp.net-web-api asp.net-mvc-routing url-routing

下面是mvc4应用程序中的routeconfig.cs文件

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

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{bizId}",
            defaults: new { controller = "Home", action = "Index", bizId = UrlParameter.Optional }
        );

        routes.MapRoute(
            "Outlet",
            "Outlet/{bizId}",
            new { controller = "Home", action = "Index" },
            new { bizId = UrlParameter.Optional }
        );

    }

当我运行应用程序时,我需要输入/ Home / Index?bizId = 1或localhost端口之后的任何Id来运行我的应用程序。它工作正常。但是,现在作为第二个route.maproute,我希望url显示为ex:localhost:49787 / Outlet?bizId = 1但这不起作用。请帮忙!提前致谢

1 个答案:

答案 0 :(得分:2)

得到了修复:

 routes.MapRoute(
            name: "Outlet",
            url: "Outlet/{bizId}",
            defaults: new { controller = "Home", action = "Index", bizId = 1 }
        );