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

前端 未结 3 1422
眼角桃花
眼角桃花 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

    you have a route on the global.asax

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

    you can define your own route like :

    controller is the cs class inside the the controllers folder.

    you can define your id - with the name you choose.

    the system will pass the value to your actionResult method.

    you can read more about this step here : http://www.asp.net/learn/mvc/tutorial-05-cs.aspx

提交回复
热议问题