views:

85

answers:

2

I've created a website with ASP.NET MVC. I have a number of static pages that I am currently serving through a single controller called Home. This creates some rather ugly URLs.

example.com/Home/About 
example.com/Home/ContactUs 
example.com/Home/Features

You get the idea. I'd rather not have to create a controller for each one of these as the actions simply call the View with no model being passed in.

Is there a way to write a routing rule that will remove the controller from the URL? I'd like it to look like:

example.com/About
example.com/ContactUs
example.com/Features

If not, how is this situation normally handled? I imagine I'm not the first person to run in to this.

+1  A: 

Add defaults for the controller names in the new statement. You don't have to have {controller} in the url.

Dr. Zim
Maybe I am being dense but I don't understand this answer. Can you expand on it?
ahsteele
cantabilesoftware added an example below
Dr. Zim
A: 

Here's what I've done previously, using a constraint to make sure the shortcuts don't conflict with other routing rules:

routes.MapRoute(
    "HomeShortcuts",
    "{action}",
    new { controller = "Home", action = "Index" },
    new { action = "Index|About|ContactUs|Features" }
);
cantabilesoftware