1

I have the following routes defined:

routes.MapRoute(
            "Content Pages",
            "{action}",
            new { controller = "Pages", action = "Index" });

routes.MapRoute(
            "Default",
            "{controller}/{action}/{id}/{title}",
             new { controller = "Home", action = "Index", 
                   id = UrlParameter.Optional, 
                   title = UrlParameter.Optional },
             new string[] { "MyCompany.Web.Controllers" });

I have a controller named Pages that has some actions like "About", "FAQ" etc that I would like to access like this: mywebsite.com/About

This currently works, but now all of my other controllers end up specifying their default action in the url. My action link for Books renders as mywebsite.com/Books/Index.

How can I modify my routes so that I can achieve this?

1 Answer 1

1

I would have a more generic route for all your other controllers like this (but put it after the Page routes below)

routes.MapRoute(
            "Content Pages",
            "{controller}",
            new { Home= "Home", action = "Index" });

and change your Pages one to be more specific for those two actions (assuming you have not got an About or Faq controller).

routes.MapRoute("About Page", "about", new { controller = "Pages", action = "About" });
routes.MapRoute("FAQ Page", "faq", new { controller = "Pages", action = "FAQ" });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.