views:

56

answers:

1

My HomeController is controlling some pages like 'Index' and some others like 'Contact', 'About Us'.

But, if I type:

www.blabla.com/

the 'Index' will be called and it works.

But, if I type:

www.blabla.com/AboutUs

it doesn't work at all! It just works if I type:

www.blabla.com/Home/AboutUs

How can I make all the actions in HomeController work without typing "Home" before them?

+3  A: 

You have to make a route that looks like this.

routes.MapRoute("AboutUs", "AboutUs",
                new
                {
                    controller = "Home",
                    action = "AboutUs"
                });

You can find your routes in your Global.asax file.

The reason for this is if you check your Global.asax file you should see a default route that works on the controller/action url route. So if you want /MyMethod you have to create a route for it.

You could also try something like.

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

This should allow you to access all of your home controller actions by just using a /.

Chad Moran
Thanks for you answer Chad! But, another question based on what you've told me... if I have 10 pages in my HomeController, i will have to create 10 new routes?? Isn't there a way to say that all actions in HomeController will be accessed without the "Home/"??
AndreMiranda
thanks, Chad!! What you've told me below "You could also try something like" just worked perfectly!Thanks, man!
AndreMiranda