I am stuck on trying to create another route in Global.asax.
I am creating dynamic pages for my website using MVC3. When I type this URL
/Home/GetPages/About%20Us
It pulls the correct Controller Method and pulls the data.
However, I am trying to modify it to this
/About%20Us
Below is the route I added to the Global file:
routes.MapRoute(
"Pages", // Route name
"{controller}/{action}/{PageName}", // URL with parameters
new { controller = "Home", action = "GetPages", PageName = UrlParameter.Optional } // Parameter defaults
);
Any help would be appreciated.
You were close; all you need to do is remove the default entry for
PageNameand change the URL template to remove the controller and action identifiers.Also, make sure this route is mapped after your other routes, otherwise it’ll prevent them from working (because just about any URL except for the root will trigger this route).