【问题标题】:How to use Bootstrap Glyphicons with @Ajax.ActionLink() Method?如何通过 @Ajax.ActionLink() 方法使用 Bootstrap Glyphicons?
【发布时间】:2016-09-21 04:00:44
【问题描述】:

在下面的代码中,我想在“动物名称”之后包含一个 Bootstrap 字形图标。

@Ajax.ActionLink("Animal Name", "_Index", new { sortOrder = ViewBag.NameSortParam, searchString = Request["searchString"] }, new AjaxOptions
           {
               HttpMethod = "GET",
               UpdateTargetId = "PartialTable",
               InsertionMode = InsertionMode.Replace
           })

有可能吗??如果不可能,是否有任何其他替代解决方案,例如:

<a href="@Url.Action("Index", "Animal", new {sortOrder = ViewBag.NameSortParam, searchString = Request["searchString"] })">
             <span style="font-size:18px">Animal Name</span>
            <i class="glyphicon glyphicon-triangle-bottom"></i>
 </a>

这被用作将 Bootstrap Glyphicons 与 @Html.ActionLink() 方法一起使用的替代方法!

【问题讨论】:

  • 不,不可能使用ActionLink()。另一种方法是编写您自己的扩展方法
  • 谢谢!!是否使用 $.ajax() 方法??
  • 没有。你需要自己编写HtmlHelper扩展方法来生成你想要的html
  • 明白了!!谢谢!!

标签: c# jquery ajax asp.net-mvc asp.net-ajax


【解决方案1】:

两年后,没有一个答案是正确的,让我分享一下。

@Ajax.ActionLink(" ", "Action", new { id = 1 }, new AjaxOptions
{   
    HttpMethod = "GET",
    InsertionMode = InsertionMode.Replace,
    LoadingElementId = "div"
},
new 
{ 
    @class = "glyphicon glyphicon-search"
});

【讨论】:

    【解决方案2】:
       @Ajax.RawActionLink(string.Format("<i class='icon'></i>Click Me"), "ActionResultName", null, new { item.Variable}, new AjaxOptions { HttpMethod = "Post", InsertionMode = InsertionMode.Replace, UpdateTargetId = "taget-div", LoadingElementId = "target-div" }, new { @class = "class" })
    

    辅助方法

       public static MvcHtmlString RawActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string controllerName, object routeValues, AjaxOptions ajaxOptions, object htmlAttributes)
        {
            var repID = Guid.NewGuid().ToString();
            var lnk = ajaxHelper.ActionLink(repID, actionName, controllerName, routeValues, ajaxOptions, htmlAttributes);
            return MvcHtmlString.Create(lnk.ToString().Replace(repID, linkText));
        }  
    

    来源:https://stackoverflow.com/a/16983575/5326667

    【讨论】:

      【解决方案3】:

      这是我想出的:

      在您的 Ajax.ActionLink 中添加带有类值的 htmlAttributes 属性并使用 javascript/jquery 更改值。

      html属性示例:

      new { @class = "expand" }
      

      脚本:

      <script>
          $(document).ready
          (
              function()
              {
                  $('.expand').html("<span class='glyphicon glyphicon-chevron-right'></span>")
              }
          )
      </script>
      

      【讨论】:

        猜你喜欢
        • 2020-11-08
        • 2016-01-12
        • 2017-10-07
        • 2014-06-07
        • 2013-10-15
        • 2023-04-11
        • 2013-12-15
        • 1970-01-01
        • 2013-08-15
        相关资源
        最近更新 更多