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.
-
If you are using index then the action is not required. Unless you set something else as the default action in your routesGarvin– Garvin2012年12月27日 03:16:30 +00:00Commented Dec 27, 2012 at 3:16
-
@Garvin - I don't understand, say I put myUrl.com/ePage/my-paramater , then isn't it going to look for the action "my-parameter" in the controller "ePage" ??? or will it just know to go to myUrl.com/ePage/Index?id=my-parameterScott Selby– Scott Selby2012年12月27日 03:19:07 +00:00Commented Dec 27, 2012 at 3:19
1 Answer 1
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.