3
votes

I am having an issue 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" }
            );

the actionlink is using the AdminDefault, when I want it to use the default controller. How do I get it to use default route without using a routelink?

To add more info. I have a simple action (home/index), it shows a view (index.cshtml), in that view I have:

@Html.ActionLink("About", "About", "Home")

Which generates a url of "/Admin/Home/About" when I want it to be "/Home/About" the defaultadmin route is so that i can create links later that go to /admin/controller/action for any administration pages, but I want the default generated urls to not be under admin.

1

1 Answers

2
votes

If you use Html.ActionLink from a view that is in an area then by default it will pass the area in to that link.

To override this you can call Html.ActionLink like so:

@Html.ActionLink("linkText", "actionName", "controllerName", new {Area = "AreaName"}, null);

where 'new {Area = "AreaName"}' are the route object values and 'null' are the html attributes.

You can therefore use 'new {Area = ""}'