wil
wil

Reputation: 2137

How can I create a C# MVC Html ActionLink that contains an icon?

I'm converting and updating a very old website to C# MVC at the moment, and, I am stuck at converting a few hyperlinks.

It used to have:

<a href="details.aspx" class="btn_red">Read More <i class="fa fa-eye"></i></a>

and, I have tried a few things without luck... The closest I have come is to just drop the icon:

@Html.ActionLink("Read More", "Details", new { id = item.ID }, new {@class= "btn_red"})

How would I go about adding the icon, and, whilst it feels the right thing to do, should I even be converting all links like this, or, should I just modify them as they will work fine?

Upvotes: 0

Views: 631

Answers (1)

David
David

Reputation: 218950

The Html.ActionLink helper method only creates a link, which is just an a element. What you're looking to do is create a nested structure, wherein an a element contains an i element. The helper method doesn't have an option for that. (It's not a particularly HTML-semantic structure, so I doubt any out-of-the-box tools are going to do that.)

You can, however, built your markup a little more manually. Something like this:

<a href="@Url.Action("Details")" class="btn_red">Read More <i class="fa fa-eye"></i></a>

Upvotes: 3

Related Questions