Search code examples
c#asp.net-mvcactionlink

How put a image inside an ActionLink


<ul class="nav navbar-nav navbar-right">      
    <li >
        <a href="/GTracker/Account/Login" id="loginLink" style="color:lightgreen">
            Login
            <img src="~/Content/Login-icon-door.png" />
        </a>
    </li>  
    <li>
        @Html.ActionLink("Log in", "Login", "Account", routeValues: null, 
                      htmlAttributes: new { id = "loginLink", style = "color:lightgreen" })
    </li>
</ul>

Both go the the right action. But can I use ActionLink helper to also include the image?

enter image description here


Solution

  • Do you want to use an ActionLink helper so that you do not have a hard coded path in your view (understandable).

    How about this:

    <a href="@Url.Action("Login", "Account")" id="loginLink" style="color:lightgreen">
        Login
        <img src="~/Content/Login-icon-door.png" />
    </a>