在我的MVC項目中,我有項目控制器和一些動作如索引。MVC RouteConfig影響Html.ActionLink()輔助方法
的RouteConfig包括:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
在一些觀點,我使用的輔助方法Html.ActionLink( 「項目」, 「索引」, 「項目」)創建索引錨行動。所以錨結果HREF會(/項目/指標)
現在,我需要映射以下靜態網址:
/IndirectItem /索引
至索引動作項目控制器默認參數(間接=真),所以RouteConfig將是:
routes.MapRoute(
name: "IndirectItem",
url: "IndirectItem/Index",
defaults: new { controller = "Item", action = "Index", indirect = true }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
看來OK和客戶端的請求被正確映射,但所有錨導致從Html.ActionLink(「項目」,「索引」, 「Item」)輔助方法映射到URL(/IndirectItem/Index)而不是(/Item/Index)。
我怎麼能解決這個問題,在不改變所有Html.ActionLink()到Html.RouteLink()或添加另一條路線爲原來的網址是什麼?
非常好的解決方案。這是一個可以應用於多種行動的動態路線。謝謝。 –
很高興,因爲你得到它的工作:)) –