Jamie Romeo
Jamie Romeo

Reputation: 255

How to redirect to index actionresult while not displaying index in the url

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?

Upvotes: 1

Views: 443

Answers (1)

DGibbs
DGibbs

Reputation: 14618

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

Upvotes: 4

Related Questions