Matt Powell Matt Powell - 10 months ago 148
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?


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>