Html.ActionLink in Layout broken in some cases #278

Imported from the CodePlex archive for reference purposes. Support for MvcCodeRouting has ended.

Reported on

Updated to the latest code this morning (after the fix for issue #276 was implemented), and discovered a new problem. Links placed in the layout sometimes return empty strings. I’ve attached a sample project that exhibits the error. Just start up the site and there will be a link to the problem page that you can click on.

In the layout there are two links: @Html.ActionLink(“Home”, “Index”, “Home”) @Html.ActionLink(“About”, “About”, “Home”)

These links generate correct urls when you are on the Home page or the About page, but when you are at the /Admin/Players/Create url, though, these links generate empty strings.

Commented on link

This behavior is by design. Routes are matches against the current BaseRoute, so if you do Url.Action(“”, “Home”) and the BaseRoute of the current route is Admin/Players then you are saying you want to link to [baseNamespace].Admin.Players.HomeController. Use an absolute controller reference, e.g. Url.Action(“”, “~Home”).