Search code examples
asp.netrazorasp.net-mvc-4razor-2

Html.Action is not creating link to View


I'm trying to get a navigation bar going for my website but I am having some trouble.

I have the following:

<li>@Html.Action( "Project Management", "ProjectManagement", "Services" )</li>

Set up to call the view, but what it seems to be doing is placing that view into the navigation bar.

Is this the proper way to link the view to the navigation bar or should I try something different?


Solution

  • What you want to use is @Html.ActionLink rather than @Html.Action.

    • @Html.ActionLink Generates a hyperlink, <a href="...">Text</a>
    • @Html.Action Executes a Controller action, i.e., returns the HTML/markup/JSON/whatever, that it's programmed to return.

    Try this code instead:

    <li>@Html.ActionLink( "Project Management", "ProjectManagement", "Services" )</li>