Matt Powell Matt Powell - 1 year ago 242
C# Question

Putting HTML inside Html.ActionLink(), plus No Link Text?

I have two questions:

  1. I'm wondering how I can display no link text when using
    in an MVC view (actually, this is

There is not an overloaded version that does not allow link text, and when I try passing in just a blank
, the compiler tells me it needs a non-empty string.

How can I fix this?

  1. I need to put
    tags within the anchor tag, but it's not working with
    . I'd like to see the following output:

    Span text

How can I put tags inside of the anchor tag in ASP.NET MVC?

Answer Source

Instead of using Html.ActionLink you can render a url via Url.Action

<a href="<%= Url.Action("Index", "Home") %>"><span>Text</span></a>
<a href="@Url.Action("Index", "Home")"><span>Text</span></a>

And to do a blank url you could have

<a href="<%= Url.Action("Index", "Home") %>"></a>
<a href="@Url.Action("Index", "Home")"></a>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download