Question

I am a bit new to the MVC so started off with MVC3 with ASPX engine. my scenario is, that when I create a controller it automatically generates an Action named "Index" so suppose if I create a "Users" Controller + some actions, it would look something like this.

UserController

  • Index
  • Add
  • Delete
  • Edit
  • other actions

Then I create another controllers named "Products", "Company", etc with lets say the same set of Actions,

So normally when I would go to the link ../Users/Index I have the logic to show all users and it would do the same for ..Product/Index and ..Company/Index etc. It would show all products and all companies respectively.

This part of story is working good.

Now what I want to achieve is, I want to get rid of /Index everywhere in the url, not just for these three controllers, but for every controller that I create in future. I want to consume "Index" Action but in a way that it doesn't need being typing everywhere. It just makes me remember of old days where there used to be /index.html.

I have seen the links like these, MVC Routing get rid of /Index in URL they suggest i change the route for a specific situation, but I want this done not just in one or two controllers but every controller there is in my app.

Thanks.

Was it helpful?

Solution

In every route, specify Index as the default action, e.g.:

routes.MapRoute(null, "{controller}/{action}/{id}",
   new { controller = "Home", action = "Index" });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top