【问题标题】:Transform MVC Html.ActionLink to plain HTML with span使用 span 将 MVC Html.ActionLink 转换为纯 HTML
【发布时间】:2015-03-30 05:19:16
【问题描述】:

我正在编写 ASPNET MVC,我想使用 Html.ActionLink 但是我希望最终的 HTML 看起来像这样

来自:

<li>@Html.ActionLink("Home", "Index", "Home")</li>

到:

<li>
    <a href="layout-variants.html">
        <i class="linecons-desktop"></i>
        <span class="title">Home</span>
    </a>
</li>

我怎样才能改变

【问题讨论】:

  • 如果你想与 Html5 更兼容,你应该使用 span 而不是 i。 Html5 中的i 与以前版本中的(语义上)不同。

标签: html asp.net asp.net-mvc


【解决方案1】:

你应该使用Url.Action()

<li>
    <a href="@Url.Action("Index","Home")">
        <i class="linecons-desktop"></i>
        <span class="title">Home</span>
    </a>
</li>

【讨论】:

    【解决方案2】:

    Url.Action("Index","Home") 是它的方式。

    See the demo

    【讨论】:

      【解决方案3】:
      public static string ActionLink(this HtmlHelper html, string url)
      {
        return "<a href="\" + url +"\"><i class=\"linecons-desktop\"></i><span class=\"title\">Home</span></a>"
      }
      

      从视图调用:@Html.ActionLink("layout-variants.html"),您可以更改项目的参数。

      【讨论】:

        猜你喜欢
        • 2011-01-25
        • 2022-01-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-08
        • 2018-05-11
        相关资源
        最近更新 更多