1

Basically, in my controller I'm redirecting to the Index action:

return RedirectToAction("", new { id = id });

This works great except for the fact that the URL bar displays controllername/index/id. I would like to be able to avoid displaying "Index" in the URL. Is this possible? And if so, how?

1

1 Answer 1

4

Add a route without the action name in your global.asax.cs:

routes.MapRoute("NoActionInURL", "ControllerName/{id}", 
       new { controller = "ControllerName", action = "Index", id = UrlParameter.Optional });
Sign up to request clarification or add additional context in comments.

3 Comments

Shouldn't it be "without the action name"? "I would like to be able to avoid displaying "Index" in the URL."
My mistake, I thought he wanted to hide the controller. Have updated.
Thanks for your answer and I'm sorry for the late reply. A question though: I'm redirecting to it using: return RedirectToAction("", new { id = id }); However when I redirect it still displays index?

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.