9

我想将链接转换为 ajax 操作链接。我不知道如何在链接文本中显示 html 元素?

这是原始链接:

<a href="#onpageanchor" id="myId" class="myClass" title="My Title."><i class="icon"></i>Click Me</a>

这是ajax操作链接:

@Ajax.ActionLink("<i class='icon'></i>Click Me", "MyActionMethod", new { id = "testId" },
                        new AjaxOptions
                        {
                            UpdateTargetId = "mytargetid"
                        }, new
                        {
                            id = "myId",
                            @class = "myClass",
                            title="My Title."
                        })

呈现的链接文本是实际的字符串:"<i class='icon'></i>Click Me</a>"

4

3 回答 3

33

晚了一年多,但这是我用的。希望它可以帮助别人。

@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));
    }  
于 2013-06-07T11:56:51.193 回答
0

我创建了 Ajax.ActionLink 来显示图像而不是链接文本

    @Ajax.ActionLink(".", "Delete_Share_Permission", "Share", new { delwhich = "one", delid = @UserSharingDetails.PK_User_Sharing_Id }, new AjaxOptions { UpdateTargetId = "sharelist", InsertionMode = InsertionMode.Replace, OnBegin = "return confirmdeleteone();" }, new { @class = "deleteButton", @id = "fna" })

申请班级

 .deleteButton {        
    background-image: url("/images/DeleteData.png");
    position: absolute;
    right: 6px;
    background-repeat: no-repeat;
    border: none;
    background-position: 50% 50%;
    margin-left: 10px;
    background-color: transparent;
    width: 13px;
    color: #ffffff !important;
    display: block;
    top: 5px;
}

我希望这段代码对你有用。

谢谢你。

于 2014-07-15T11:05:09.843 回答
0
@Ajax.ActionLink(" Name", "AjaxGetAllUsers", "Admin", new { sortBy = ViewBag.SortByName, search = Request.QueryString["search"] }, new AjaxOptions() { UpdateTargetId = "userlist", InsertionMode = InsertionMode.Replace, HttpMethod = "GET" }, new { @class = "fa fa-sort" })
于 2016-09-06T17:29:22.630 回答