ASP.NET Actionlink with glyphicon and text with different font

后端 未结 10 883
臣服心动
臣服心动 2020-12-04 15:12

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

With this code:


    @H         


        
相关标签:
10条回答
  • 2020-12-04 15:52

    How about using Html.BeginForm with a FormMethod.Get / FormMethod.Post

    @using (Html.BeginForm("Action", "Controller", new { Area = "" },
    FormMethod.Get, htmlAttributes: new { title = "SomeTitle" }))
    {   
       <button type="submit" class="btn-link" role="menuitem">
       <i class="glyphicon glyphicon-plus-sign"></i>Create New</button>
    }
    
    0 讨论(0)
  • 2020-12-04 15:55

    Try it!

    @Html.ActionLink(" Cerrar sesión", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" , @class = "glyphicon glyphicon-log-in" })
    
    0 讨论(0)
  • 2020-12-04 16:01

    You can use simple extension:

    private static readonly String SPAN_FORMAT = "<span class=\"{0}\" aria-hidden=\"true\"></span>";
    private static readonly String A_END = "</a>";
    public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues, String iconName, object htmlAttributes = null)
    {
        var linkMarkup = htmlHelper.ActionLink(linkText, actionName, routeValues, htmlAttributes).ToHtmlString();
        if (!linkMarkup.EndsWith(A_END))
            throw new ArgumentException();
    
        var iconMarkup = String.Format(SPAN_FORMAT, iconName);
        return new MvcHtmlString(linkMarkup.Insert(linkMarkup.Length - A_END.Length, iconMarkup));
    }
    

    Usage:

    Html.ActionLink(" ", "DeleteChart", new { Id = _.Id }, "glyphicon glyphicon-trash")
    
    0 讨论(0)
  • 2020-12-04 16:06

    Let's have a try on this. Let me know if it is working .Thanks

    <style>
       span.super a
      {
          font: (your application font) !important;
      }
    
    </style>
    
    <span class="super">
        @Html.ActionLink("  Create New", "Create", null, new { @class = "btn btn-warning glyphicon glyphicon-plus-sign" })
    </span>
    
    0 讨论(0)
提交回复
热议问题