tags:

views:

193

answers:

3

I need the text of a link wrapped with <span> as in:

<a href="/foo.html"><span>Edit Group</span></a>

Can I do that with Html.ActionLink? This doesn't work:

<%=Html.ActionLink("<span>Edit Group</span>", "Edit", New With {.id = "bar"})%>

It just HTML encodes the < and > as &lt; and &gt;.

Is there a simple solution, or should I build the links by hand with Url.Action?

This is for use with jQuery-UI Tabs. Tab labels need to be wrapped in <span> to get animation when AJAX content is loading.

+2  A: 

You'll need to do it with Url.Action, there's no way with Html.ActionLink as far as I know.

womp
+5  A: 

You can use the Url.Action helper method as a workaround (in case no other answers better fit your needs).

For example, the following can be in marked up in your view:

<a href="<%= Url.Action("Edit", 
                        New With {.id = "bar"}) %>">
 <span>Edit Group</span>
</a>
David Andres
Thanks. Yes, that's what I ended up doing.
Slack
+2  A: 

You can also roll your own HtmlHelper Extension Method, I actually prefer this method as you can control the placement of ids, classes, and other attributes like a title.

Here is a blog post that I put together on the subject.

SyntaxC4