Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Actionlink with glyphicon and text with different font

I want to present a button with @Html.ActionLink but i need to have my application font in the text.

With this code:

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

I get my button but the Create New text appears with the glyphicon font-family.

Putting the glyphicon classes in the span doesn't change anything

like image 267
e4rthdog Avatar asked Oct 03 '14 06:10

e4rthdog


3 Answers

You should not add the glyphicon class to the a-tag.

From the Bootstrap website:

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.

In other words the correct HTML for this to work the way you want would be: <a href="#" class="btn btn-warning">test <span class="glyphicon glyphicon-plus-sign"></span></a>

This makes the Html.ActionLink helper unsuitable. Instead you could use something like:

<a href="@Url.Action("Action", "Controller")" class="btn btn-warning">
    link text 
    <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>
</a>
like image 133
Robban Avatar answered Nov 09 '22 09:11

Robban


This works for me in MVC 5:

@Html.ActionLink(" ", "EditResources", "NicheSites", new { ViewBag.dbc, item.locale, ViewBag.domainId, domainName = ViewBag.domaiName }, new {@class= "glyphicon glyphicon-edit" })

The first parameter cannot be empty or null or it will blow.

like image 23
Norbert Norbertson Avatar answered Nov 09 '22 08:11

Norbert Norbertson


It might be better to just write out the HTML rather than try to make it work with HtmlHelper.ActionLink...

<span>
    <a href="@Url.Action("Create")" class="btn btn-warning">
        <span class="glyphicon glyphicon-plus-sign"></span>
        Create New
    </a>
</span>
like image 9
Anthony Chu Avatar answered Nov 09 '22 09:11

Anthony Chu