asp.net-mvc - 带有字形图标和不同字体文本的 ASP.NET Actionlink

标签 asp.net-mvc twitter-bootstrap razor glyphicons

我想用 @Html.ActionLink 呈现一个按钮,但我需要在文本中包含我的应用程序字体。

使用此代码:

<span>
    @Html.ActionLink("  Create New", "Create", null, new { @class = "btn btn-warning glyphicon glyphicon-plus-sign" })
</span>

我得到了按钮,但新建文本与字形字体系列一起出现。

将字形图标类放入范围中不会改变任何内容

最佳答案

您不应将 glyphicon 类添加到 a 标记。

来自 Bootstrap 网站:

Don't mix with other components Icon classes cannot be directly combined with other components. They should not be used along with other classes on the same element. Instead, add a nested <span> and apply the icon classes to the <span>.

Only for use on empty elements Icon classes should only be used on elements that contain no text content and have no child elements.

换句话说,按照您想要的方式工作的正确 HTML 是:<a href="#" class="btn btn-warning">test <span class="glyphicon glyphicon-plus-sign"></span></a>

这使得Html.ActionLink helper 不合适。相反,你可以使用类似的东西:

<a href="@Url.Action("Action", "Controller")" class="btn btn-warning">
    link text 
    <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>
</a>

关于asp.net-mvc - 带有字形图标和不同字体文本的 ASP.NET Actionlink,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26174013/

相关文章:

c# - Restful 服务 URL 参数 - 服务堆栈

javascript - Multieple CheckBoxes 根据选中的复选框动态选中取消选中 + MVC3 + jQuery/Javascript

javascript - jQuery 在动态加载内容并使用 .replaceWith() 后不应用样式

asp.net-mvc - 拒绝自定义角色

javascript - postcss-import grunt 插件不工作

html - 显示具有固定高度和自定义宽度的 Logo

c# - 从 AspNetCore TestHost 运行时编译 Razor 期间出现 CompilationFailedException

c# - 计算未在 Razor 中正确显示

asp.net - MVC, Entity Framework 从多个模型中选择数据

asp.net-mvc - 在 Asp.NET MVC 中突出显示导航菜单?