0

I render a menu widget inside the header of a master layout.

_Layout.cshtml

@Html.Action("Menu", "Menu", new { area = "Application" })

FullMenu.cshtml

<div class="navbar-collapse collapse">
    <ul class="nav navbar-nav">
        <li><a href='#'><span class='glyphicon glyphicon-education'></span></a></li>
        <li>@Html.ActionLink("Projects", "Index")</li>
        <li>@Html.ActionLink("Tests", "Index" })</li>
    </ul>
    @Html.Partial("_LoginPartial")
</div>

MenuController.cs

public class MenuController : Controller
{
    [ChildActionOnly]
    public ActionResult Menu()
    {
        string controller = (string) ControllerContext.ParentActionViewContext.RouteData.Values["controller"];
        if (controller == "Projects")
        {
            return PartialView("StartMenu");
        }
        else
            return PartialView("FullMenu");
    }
}

This is the rendered output in the browser

enter image description here

Why has the rendered hyperlinks a modified Controller name? Even more those links applied the Controller name of the widget itself => "Menu" Why is that?

Elisabeth
  • 20,496
  • 52
  • 200
  • 321
  • 1
    Try @Html.ActionLink("Projects", "Index", "Projects") in your FullMenu.cshtml – Praveen Paulose Nov 08 '15 at 20:10
  • 2
    ok those links worked before, since I put them in the "widget" I need to declare the full route:
  • @Html.ActionLink("Projects", "Index", "Projects", new { area = "Application" }, new { })
  • , thanks for the hint! – Elisabeth Nov 08 '15 at 20:15