user9993
user9993

Reputation: 6170

How to insert a HTML character into this Html.ActionLink?

I'm using the following code to generate this:

<p>@Html.ActionLink("Read", "Index", "News", null, new { @class = "btn btn-default" })</p>

enter image description here

But I want to make a button that looks like this (with the use of HTML character &raquo;): enter image description here

However when I do the following:

<p>@Html.ActionLink("Read &raquo;", "Index", "News", null, new { @class = "btn btn-default" })</p>

I get this:

enter image description here

How do I fix this?

Upvotes: 7

Views: 3839

Answers (3)

Polynomial Proton
Polynomial Proton

Reputation: 5135

Other solutions given here work. But just in case you are wondering, what to do if you dont have the special character on keyboard, here it goes:

You can either use

<a href='@Url.Action("Index", "News")' class="btn btn-default">Read &raquo;</a>

OR

@Html.ActionLink(HttpUtility.HtmlDecode("Read &raquo;"), "Index", "News", null, new { @class = "btn btn-default" })

Upvotes: 12

dub stylee
dub stylee

Reputation: 3342

<p>@Html.ActionLink("Learn More »", "Index", "News", null, new { @class = "btn btn-default" })</p>

As @MatteoSp said, just use the actual character in your string. The above ActionLink will give you a button as you desired.

Upvotes: 0

MatteoSp
MatteoSp

Reputation: 3048

The text will be encoded by ActionLink() implementation, so you don't need to do it. Just use that char in the string.

Upvotes: 2

Related Questions