Whenever I use Html.ActionLink it always Html encodes my display string. For instance I want my link to look like this:
<a href="/posts/422/My-Post-Title-Here">More…</a>
it outputs like this: More…
&hellip is "..." incase you were wondering.
However the actionlink outputs the actual text "…" as the link text. I have the same problem with if I want to output this:
<a href="/posts/422/My-Post-Title-Here"><em>My-Post-Title-Here</em></a>
I wind up with: <em>My-Post-Title-Here</em>
Any idea how to do this?
It looks like ActionLink always uses calls HttpUtility.Encode on the link text. You could use UrlHelper to generate the href and build the anchor tag yourself.
<a href='@Url.Action("Posts", ...)'>More…</a>
Alternatively you can "decode" the string you pass to ActionLink. Constructing the link in HTML seems to be slightly more readable (to me) - especially in Razor. Below is the equivalent for comparison.
@Html.ActionLink(HttpUtility.HtmlDecode("More…"), "Posts", ...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With