MVC:分页改进URL

时间:2023-03-09 18:25:16
MVC:分页改进URL

http://localhost/?page=2

 
 

可以根据"可组合URL"创建一种更具吸引力的URL方案:

http://localhost/page2

 
 

public static void RegisterRoutes(RouteCollection routes)  

        {  

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");  

  
 

            routes.MapRoute(  

            name: null,  

            url: "Page{page}",  

            defaults: new { Controller = "Product", action = "List" }  

            );  

  
 

            routes.MapRoute(  

                name: "Default",  

                url: "{controller}/{action}/{id}",  

                defaults: new { controller = "Product", action = "List", id = UrlParameter.Optional }  

            );  

        }  

 
 

重要的是在已有的
Default 路由之前天津唉纸条路由。