views:

87

answers:

3

At the moment I have just this route defined

 routes.MapRoute(
                "Default",                                                
                "{controller}/{action}/{id}",                           
                new { controller = "Home", action = "Index", id = "" } 
                );

I want to map the /Home/Action1/id to just /Action1/id anybody knows how ?

+2  A: 

look at this question How to Route /About to /Home/About

It's not (exactly) the answer but I think it gives you the answer in reverse.

griegs
+2  A: 
 routes.MapRoute(
                "NewRoute",                                                
                "{id}",                           
                new { controller = "Home", action = "Index", id = "" } 
                );

try that, as long as you default the controller and action it should work. Don't forget when generatig links with Html.Action to use the new route name.

Apologies for formatting written on my iPhone

danswain
+1  A: 

You may have to be careful with a route like you're asking for because it may catch more than is intended.

One workaround is to restrict that route by using constraints if possible.

E.g. Check that id is numeric...

routes.MapRoute("ActionRoute", 
         "{action}/{id}",
         new { controller = "Home", action = "Index", id="1" },
         new { id = @"\d{1,6}" }
);

That way you can still specify your generic default route at the end to catch the rest of the routes on the site if needed.

kervin