Scott Selby
Scott Selby

Reputation: 9580

parameters in url in asp.net mvc

I know this can be done, but don't even know what its called to find a good tutorial from Google. I am using ASP.Net MVC4 and I have a controller called ePage, right now I can access what I want from a URL like this

  http://www.myUrl.com/ePage/{ACTION}/{PARAMETER as "id"}

how can I change the routing so that (just for this controller if possible) it is read like this

  http://www.myUrl.com/ePage/{PARAMETER}

I will always be using "Index" as Action for now.

If there is a simple answer to do that'd be awesome , if not just a point to the right direction for me to read and figure out.

Upvotes: 1

Views: 373

Answers (1)

rexcfnghk
rexcfnghk

Reputation: 15502

In your Global.asax.cs under the RegisterRoutes method, you can try adding:

routes.MapRoute("MyNewRoute", "ePage/{param}", new { 
    controller = "ePage",
    action = "Index",
});

Your Index method must have an argument named param so that the routing will match.

Upvotes: 4

Related Questions