如何使用@ Ajax.ActionLink()方法使用Bootstrap Glyphicons?

时间:2016-09-21 04:00:45

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

在下面的代码中,我想在“动物名称”之后包含一个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>

使用@ Html.ActionLink()方法将其作为使用Bootstrap Glyphicons的替代方法!

3 个答案:

答案 0 :(得分:0)

   @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

答案 1 :(得分:0)

以下是我提出的建议:

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

html属性示例:

new { @class = "expand" }

脚本:

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

答案 2 :(得分:0)

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

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