创建了链接文本的html元素ActionLink的AJAX [英] create ajax actionlink with html elements in the link text

查看:784
本文介绍了创建了链接文本的html元素ActionLink的AJAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个链接转换为一个ajax操作链接。我无法弄清楚如何显示的链接文本中的HTML元素?

I would like to convert a link to an ajax action link. I can't figure out how to display html elements within the link text?

下面是原文链接:

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

下面是阿贾克斯ActionLink的:

Here is the ajax actionlink:

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

呈现的链接文本是实际的字符串:&LT; I类='图标'&GT;&LT; / I&gt;点击ME&LT; / A&gt;中

推荐答案

较去年末和一切,但,这是我使用。希望它可以帮助别人。

over a year late and everything but this is what I use. Hope it helps someone else.

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

然后助手...

Then the helper...

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

这篇关于创建了链接文本的html元素ActionLink的AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆