Asp.net mvc actionlink using wrong route
I have a problem with html.actionlink. I have two routes defined:
routes.MapRoute(
"AdminDefault",
"Admin/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Page", action = "Details", id = "0" }
);
actionlink uses AdminDefault when I want it to use the default controller. How do I get it to use the default route without using routing?
To add more information. I have a simple action (home / index), it shows a view (index.cshtml), in this view I have:
@Html.ActionLink("About", "About", "Home")
Which generates the URL "/ Admin / Home / About" when I want it to be "/ Home / About", the defaultadmin route so that I can create links later that go to / admin / controller / action for any administrative pages, but I want the generated urls not to be under admin by default.
source to share
If you are using the Html.ActionLink from a view that is in scope, then by default it will pass the scope to this link.
To override this, you can call Html.ActionLink like this:
@Html.ActionLink("linkText", "actionName", "controllerName", new {Area = "AreaName"}, null);
where 'new {Area = "AreaName"}' are route object values and 'null' are html attributes.
Therefore you can use 'new {Area = ""}'
source to share