1

I have the following URL map in Global.asax.cs:

 routes.MapRoute("RejectRevision", "{controller}/{Index}/{revisionId}"
        , new { controller = "RejectRevision", action = "Index", revisionId = "" });

But I don't want to have to type http://localhost:9999/RejectRevision/Index/1, I want to be able to type in http://localhost:9999/RejectRevision/1 in order to hit the Index action on the RejectRevision controller. What am I missing here?

THanks.

gangelo
  • 3,034
  • 4
  • 29
  • 43

1 Answers1

1

Put this before your Default route:

routes.MapRoute(
    "RejectRevision",
    "{controller}/{revisionId}",
    new { 
        controller = "RejectRevision", 
        action = "Index", 
        revisionId = UrlParameter.Optional }
);

If this is placed before your Default route, a request of /RejectRevision/1 will map to RejectRevisionController.Index() action method.

Or, if this is the only Controller/Action method you want to be mapped like this, then you can use a literal instead of a parameter for the route:

routes.MapRoute( 
    "RejectRevision", 
    "RejectRevision/{revisionId}", 
    new {  
        controller = "RejectRevision",  
        action = "Index",  
        revisionId = UrlParameter.Optional } 
); 
  • ty. what is the significance of putting this before the Default route? – gangelo Feb 03 '12 at 02:02
  • @gangelo The significance of putting this before the Default route is because routes are analyzed sequentially, and the first match is the route that is utilized. –  Feb 03 '12 at 02:03