[RESOLVED]custom url Routing MVC 4

I need to rout custom url
I need To Change Url From  localhost:2440/Page/?PageTitle=About_Us  to url:
localhost:2440/About_Us
 My Controller shown below:      
///url: localhost:2440/Page/?PageTitle="About_Us"
        public ActionResult Page(string PageTitle)
        {
             

        }
thanks

What is the name of your Controller in this case? Is it PageController?

public class RouteConfig
{
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            // This route will do what you need
            routes.MapRoute(
             name: "Page",
             url: "{PageTitle}",
             defaults: new { controller = "Page", action = "Page", PageTitle = UrlParameter.Optional }
            );

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
}

The first route provided above will capture the path that you need and would route "/About_Us" as follows :

Leave a Reply