views:

168

answers:

2

I would like that the Index action doesn't appear in the url.

For example, I would like to see

www.mywebsite.com/MyController/1

instead of

www.mywebsite.com/MyController/Index/1

Is there something special I have to do in the Html.ActionLink tag or in the global.aspx file ?

+1  A: 

Try this for your routes.

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

It sets the action to the default of "Index"

Nick Berardi
I am also trying to acheive this, but am getting the following error in MVC 2: The route URL cannot start with a '/' or '~' character and it cannot contain a '?' character.Parameter name: routeUrl. any ideas
Mark Redman
A: 

yes you can by modifying your route like this:

 routes.MapRoute(
                "Default",                                              // Route name
                "{controller}/{id}",                           // URL with parameters
                new { controller = "MyController", action = "Index", id = 1 }  // Parameter defaults
            );
Marwan Aouida