![](/img/trans.png)
[英]Asp.Net MVC Routes - Handle Multiple routes with the same signature?
[英]Asp.net MVC using the same controller for multiple routes
我有一個像這樣的簡單控制器(不,不是,但說我可以)
public class SomethingController : Controller {
public ActionResult Method1() {
return View("Something1");
}
public ActionResult Method2() {
return View("Something2");
}
}
現在,我想將此控制器用於兩條不同的路線:
public static void RegisterRoutes(RouteCollection routes) {
routes.MapRoute("Route 1", "Route1/{action}", new { controller = "Something" });
routes.MapRoute("Route 2", "Route2/{action}", new { controller = "Something" });
}
直到這里,沒什么特別的。 然而,我的觀點里Something1
我現在不願意做的
Html.ActionLink("Do Something", "Method2")
並且這應該呈現<a href="Route1/Method2"...
或<a href="Route2/Method2"...
,具體取決於導致顯示該視圖的控制器的路由。 如何才能做到這一點?
使用Html.RouteLink
而不是Html.ActionLink
。 它允許您指定路由名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.