asp.net mvc 4 - Html.ActionLink generates the wrong link based on routes.MapRoute -
i guess still don't understand routing.
i have 3 controllers
- admincontroller
- dashboardcontroller
- projectgroupscontroller
for dashboard, want url /dashboard/. admin section, however, want 2 different controllers. /admin/overview should using admincontroller, , /admin/projectgroups/ should using projectgroupscontroller.
this how routing looks like
routes.maproute( name: "adminoverivew", url: "admin/overview", defaults: new { controller = "admin", action = "overview" }, namespaces: new[] { "com.controllers" } ); routes.maproute( name: "adminsubs", url: "admin/{controller}/{action}/{id}", defaults: new { action = "index", id = urlparameter.optional }, namespaces: new[] { "com.controllers" } ); routes.maproute( name: "default", url: "{controller}/{action}/{id}", defaults: new { controller = "login", action = "index", id = urlparameter.optional }, namespaces: new[] {"com.controllers"} ); *note, reason 2nd route because have many more controllers under admin section.
it's working.. except, url html.actionlink generates wrong. @html.actionlink("dashboard", "index", "dashboard"........) generates /admin/dashboard when should /dashboard.
however, @html.actionlink("project groups", "index", "projecgroups".....) generates correct url /admin/projectgroups
if take out 2nd routes.maproute (adminsubs), situation reversed. dashboard gets right url, /dashboard project groups becomes /projectgroups when should remain /admin/projectgroups
what gives?
i think need few more explicit routes, since router doesn't know difference between "catch all" of admin/{controller}/{action}/{id} , {controller}/{action}/{id}. first matched pattern 1 uses.
you either need rid of admin/{controller}/{action}/{id} , under admin prefix needs explicitly assigned route, or opposite, remove {controller}/{action}/{id} route, , explicitly create routes should apart of root directory.
Comments
Post a Comment