How do I bypass the HTML encoding when using Html.ActionLink in Mvc?

前端 未结 5 1399
醉酒成梦
醉酒成梦 2020-12-08 02:27

Whenever I use Html.ActionLink it always Html encodes my display string. For instance I want my link to look like this:



        
5条回答
  •  太阳男子
    2020-12-08 03:01

    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.

    More…
    

    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", ...)
    

提交回复
热议问题