【问题标题】:How to insert a HTML character into this Html.ActionLink?如何在这个 Html.ActionLink 中插入一个 HTML 字符?
【发布时间】:2015-08-16 22:33:42
【问题描述】:

我使用下面的代码来生成这个:

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

但我想制作一个看起来像这样的按钮(使用 HTML 字符 &amp;raquo;):

但是当我执行以下操作时:

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

我明白了:

我该如何解决这个问题?

【问题讨论】:

    标签: c# html css asp.net-mvc twitter-bootstrap


    【解决方案1】:

    此处给出的其他解决方案有效。但是,如果您想知道,如果键盘上没有特殊字符该怎么办,这里是:

    你可以使用

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

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

    【讨论】:

      【解决方案2】:
      <p>@Html.ActionLink("Learn More »", "Index", "News", null, new { @class = "btn btn-default" })</p>
      

      正如@MatteoSp 所说,只需在字符串中使用实际字符即可。上面的ActionLink会给你一个你想要的按钮。

      【讨论】:

        【解决方案3】:

        文本将由 ActionLink() 实现进行编码,因此您无需这样做。只需在字符串中使用该字符即可。

        【讨论】:

          猜你喜欢
          • 2021-09-01
          • 1970-01-01
          • 2017-08-24
          • 2011-03-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-08-18
          • 2015-03-13
          相关资源
          最近更新 更多