How can I create a friendly URL in ASP.NET MVC?

前端 未结 3 1413
眼角桃花
眼角桃花 2020-11-28 03:23

How do I generate friendly URLs within the ASP.NET MVC Framework? For example, we\'ve got a URL that looks like this:

http://site/catalogue/BrowseByStyleLevel/1         


        
3条回答
  •  爱一瞬间的悲伤
    2020-11-28 03:39

    This is how I have implemented the slug URL on my application. Note: The default Maproute should not be changed and also the routes are processed in the order in which they're added to the route list.

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

提交回复
热议问题