2011-09-13 33 views
8

Tôi có một bản đồ đường bay như:Thêm tuyến hơn để ASP.NET MVC Global.asax

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



    } 

nhưng tôi muốn thêm URL đường hơn, làm thế nào tôi có thể làm điều đó?

Trả lời

8

Chỉ cần thêm một 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 = "" } 
); 

Tôi đề nghị bạn đi qua this excellent post trên định tuyến bởi Gu.

Các vấn đề liên quan