views:

64

answers:

1

I have a simple controller like this (no, not really, but let's say I do)

public class SomethingController : Controller {
    public ActionResult Method1() {
        return View("Something1");
    }

    public ActionResult Method2() {
        return View("Something2");
    }
}

Now I want to use this controller with two different routes:

public static void RegisterRoutes(RouteCollection routes) {
    routes.MapRoute("Route 1", "Route1/{action}", new { controller = "Something" });
    routes.MapRoute("Route 2", "Route2/{action}", new { controller = "Something" });
}

Up until here, nothing special. However, inside my view Something1 I now want to do do

Html.ActionLink("Do Something", "Method2")

and this should render <a href="Route1/Method2"... or <a href="Route2/Method2"..., depending on which route led to the controller that displayed the view. How can this be done?

+2  A: 

Use Html.RouteLink instead of Html.ActionLink. It lets you specify the route name.

Craig Stuntz
@Obalix: Really? How would that work? I thought it would then only find a controller with the name Route1Controller. Can you elaborate?
erikkallen