0
我有以下路線,並在瀏覽器中輸入它們正常工作正常,但如果我使用Html.ActionLink,它會嘗試使用DefaultStuff路由。Mvc行動鏈接不使用正確的路線
路線
_routes.MapStuffRoute(
"DefaultStuff",
"stuff/{controller}/{id}",
new { id = UrlParameter.Optional },
new[] { typeof(BaseApiController).Namespace });
_routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { typeof(BaseController).Namespace });
頁
@Html.ActionLink("Job Queues", "Index", "Job") // generates http://localhost/stuff/job?action=Index
我缺少什麼,讓ActionLink的產生http://localhost/stuff/index。反轉路線的ActionLink是正確的,但東西不起作用。請注意,StuffRoute根據請求中的信息設置操作名稱。
嚴格來說,對於要解析爲路由的動作,路由必須與動作相對應,如您的示例所示。在OP的例子中,{action}被替換爲{{}},這將導致路由解析器失敗 – Mgetz 2012-02-29 20:58:53
Action根據請求中的元數據在GetRouteData中動態設置。 – Thad 2012-02-29 21:09:39
看看routedebugger。它可以幫助您解決這些問題:http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx – 2012-02-29 21:16:43