gpt4 book ai didi

asp.net-mvc - 使用链接文本中的 html 元素创建 ajax actionlink

转载 作者:行者123 更新时间:2023-12-02 09:13:47 24 4
gpt4 key购买 nike

我想将链接转换为 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>"

最佳答案

晚了一年多,除了这就是我使用的一切。希望它对其他人有帮助。

@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));
}

关于asp.net-mvc - 使用链接文本中的 html 元素创建 ajax actionlink,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12008899/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com