5

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 ?

2 Answers 2

3

Try this for your routes.

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

It sets the action to the default of "Index"

Sign up to request clarification or add additional context in comments.

1 Comment

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
0

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

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.