Melursus
Melursus

Reputation: 10618

Asp.Net MVC don't show Index action in url

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 ?

Upvotes: 5

Views: 5034

Answers (2)

user434917
user434917

Reputation:

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
            );

Upvotes: 0

Nick Berardi
Nick Berardi

Reputation: 54894

Try this for your routes.

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

It sets the action to the default of "Index"

Upvotes: 3

Related Questions