我有4條路由定義了5個不同的URL。與RouteDebugger測試了很多,但無法解決。路由在我的asp.net應用中不起作用
的問題是,前2個鏈接始終使用{控制器}/{行動}/{ID}這條路線是目錄root1而不能重定向到正確的頁面。
鏈接
@Html.ActionLink("Go Index by name", "Page", "Home", new { name="contact"}, null)
@Html.ActionLink("Go Index by id", "Index", "Admin", new { id=2}, null)
@Html.ActionLink("Go Index by id and name", "Page", "Home", new { name = "contact", id = 2 }, null)
@Html.ActionLink("Root Admin", "Index", "Admin")
@Html.ActionLink("Root", "Index", "Home")
這裏是Map.Route
routes.MapRoute("root1",
"{controller}/{action}/{id}",
new { controller = "Admin", action = "Index" });
routes.MapRoute("root2",
"{controller}/{action}/{name}",
new { controller = "Home", action = "Page" });
routes.MapRoute("root3",
"{controller}/{action}/{name}/{id}",
new { controller = "Home", action = "Page" });
routes.MapRoute("root4",
"{controller}/{action}/{name}",
new { controller = "Home", action = "Index", name = UrlParameter.Optional });
感謝您的回覆。如何處理@ Html.ActionLink(「Root Admin」,「Index」,「Admin」)路徑問題。我不想分配id = 0來使其工作。請任何解決方案? – Pirzada 2011-06-07 15:00:37
@pirzada,我不明白是什麼問題 - 該鏈接與'root4'相匹配,並顯示爲「http:// foo.com/Admin」,我相信這是正確的事情 – Beno 2011-06-07 23:06:13