Brendan Vogt
Brendan Vogt

Reputation: 26028

How to add a span tag in an a tag using Html.ActionLink

How do you add a span tag inside of an a tag using Html.ActionLink? Is something like this at all possible?

I am using ASP.NET MVC 4 together with Twitter Bootstrap version 3.

I have a drop down menu and the HTML looks like this:

<ul class="nav navbar-nav">
     <li class="@(Model.Equals("Home") ? "active" : "")">
          <a href="#">
               <span class="glyphicon glyphicon-home"></span> Home
          </a>
     </li>
</ul>

I was wanting to do the link like this:

<li>@Html.ActionLink("Home", "Index", "Home")</li>

But there is a span tag in the mix of things which makes it a bit more complex.

I can probably also use the following:

<a href="@Url.Action("Index", "Home")">
     <span class="glyphicon glyphicon-home"></span> Home
</a>

Curious to know if the above is possible?

Upvotes: 6

Views: 7043

Answers (1)

alexmac
alexmac

Reputation: 19607

Your variant with Url.Action("Index", "Home") is correct and possible. Url.Action returns the url, so it can be used in a href.

Upvotes: 2

Related Questions