Reputation: 1014
I got website templates and using it for my website. I am new to asp.net mvc 3 and razor. It is very difficult to modify html tag using html helper. How can I place the span tag between anchor tag using ActionLink Helper. I have used razor and html helper for producing link. I want to produce following tags:
<li><a href="Account/LogOff" title="Logout"><span class="glyph logout"></span> Logout</a></li>
I have try this
<li>@Html.ActionLink("<span class='glyph logout'></span> Log out", "LogOff", "Account") </li>
I am confuse how to do that. It is not the correct way that produces span tag as string. How can I produce correct tags.
Upvotes: 1
Views: 2810
Reputation: 1656
What you want to use is @Url.Action to create the URL while having your custom HTML.
<li>
<a href="@Url.Action("LogOff","Account")" title="Logout">
<span class="glyph logout"></span> Logout
</a>
</li>
This way you have control over the URL and be able to add your own custom HTML. @Html.ActionLink doesn't allow you to add custom HTML inside the tags natively.
Upvotes: 5
Reputation: 408
If you need to customize, what's inside your anchor tag, you should use the Html.Action method instead of the Html.ActionLink
<li>
<a href="@Html.Action("LogOff", "Account")" title="Logout">
<span class="glyph logout"></span> Log
</a>
</li>
Upvotes: 1