简体   繁体   English

如何在链接ASP.NET中添加图标?

[英]How to add icon in link ASP.NET?

I have the following code: 我有以下代码:

 @Ajax.ActionLink("Settings", "SettingsPopup", "Settings",
                new { area = "Customer" },
                new AjaxOptions()
                {
                    HttpMethod = "Get",
                    UpdateTargetId = "settings-content",
                    InsertionMode = InsertionMode.Replace,
                    OnSuccess = "settingsPopupLoaded",
                    AllowCache = true
                },
                new { @class = "profile-right__a icon-help" })

I need to add <i class="sub"></i> element inside this liks as: 我需要在此liks中添加<i class="sub"></i>元素,如下所示:

<a href=""><i class="sub"></i></a>

How to do this? 这个怎么做?

When you want to have customized markup but still want the ajaxy behavior. 当您想要自定义标记但仍然想要ajaxy行为时。 You can simply use jQuery to wire up that (That is what the ajax helpers also does) 您可以简单地使用jQuery进行连接(这也是ajax助手的功能)

<a class="ajaxy" targetid="settings-content"
   href="@Url.Action("settingsPopup","Settings",new { area="Customer"})">
                <span class="glyphicon glyphicon-user text-@userLevel"></span>
</a>

The javascript will be quite simply, simply look for the elements with the css class "ajaxy", make an ajax call using jQuery $.get method and update the DOM element with the result coming back. javascript将非常简单,只需使用css类“ ajaxy”查找元素,使用jQuery $.get方法进行ajax调用,并更新DOM元素,并返回结果。

function settingsPopupLoaded(e) {
    console.log('settingsPopupLoaded', e);
}
$(function () {

    $(".ajaxy").click(function (e) {
        e.preventDefault();
        var _this = $(this);
        $.get(_this.attr("href"), function (res) {
            var tId = _this.attr("targetid");
            $("#" + tId).html(res);
            settingsPopupLoaded(res);    
        });
    });
});

You can also use $.load method if it is simply updating the DOM element with the response from the ajax call. 如果仅使用ajax调用的响应更新DOM元素,则也可以使用$.load方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM