2

下面設置自定義路徑routeconfig.cs是mvc4應用我routeconfig.cs文件在MVC 4

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 } 
     ); 

    } 

當我運行應用程序,我需要輸入/首頁/指數?bizId = 1或任何在localhost端口後運行我的應用程序。它工作正常。但是,現在作爲第二個route.maproute,我希望URL顯示爲ex:localhost:49787/Outlet?bizId = 1,但這不起作用。請幫忙!在此先感謝

+0

試着將你的第二個途徑在首位 –

+0

試過了,沒變化 – Priyanka

回答

2

得到了修復:

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