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", "M开发者_运维技巧ethod2")
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?
Use Html.RouteLink instead of Html.ActionLink. It lets you specify the route name.
加载中,请稍侯......
精彩评论