将CSS类应用于Razor中的HTML Action Link

时间:2017-02-11 12:28:33

标签: html css asp.net-mvc razor html.actionlink

我有以下HTML代码:

<li>
  <a href="dashboard.html"><i class="fa fa-dashboard fa-fw"></i> Dashboard</a>
</li>

代码将菜单项显示为以下图像:

enter image description here

我想要的是用Razor代码中的@ Html.ActionLink替换链接,我试试这个:

<li>
  <i class="fa fa-dashboard fa-fw">@Html.ActionLink("Dashboard", "Index", "Home")</i>
</li>

但不幸的是,它将菜单项显示为:

enter image description here

也尝试过:

<li>
   @Html.ActionLink("Dashboard", "Index", "Home", new { @class = "fa fa-dashboard fa-fw" })
</li>

样式覆盖文本字体并将结果显示为:

enter image description here

任何建议!

先谢谢

1 个答案:

答案 0 :(得分:3)

试试这个:

<li>
    <a href="@Url.Action("Dashboard", "Home")">
        Dashboard <i class="fa fa-dashboard fa-fw"></i> 
    </a>
</li>