Asp.net mvc ajax.actionlink帮助程序有问题,返回字符串

Asp.net mvc ajax.actionlink帮助程序有问题,返回字符串,asp.net-mvc,asp.net-mvc-3,razor,Asp.net Mvc,Asp.net Mvc 3,Razor,我正在使用MVC3和Razor。 我有以下助手: public static class ImageActionLinkHelper { public static string ImageActionLink(this AjaxHelper helper, string imageUrl, string actionName, object routeValues, AjaxOptions ajaxOptions) { var b

我正在使用MVC3和Razor。 我有以下助手:

public static class ImageActionLinkHelper
    {
        public static string ImageActionLink(this AjaxHelper helper, string imageUrl, string actionName, object routeValues, AjaxOptions ajaxOptions)
        {
            var builder = new TagBuilder("img");
            builder.MergeAttribute("src", imageUrl);
            builder.MergeAttribute("alt", "");
            var link = helper.ActionLink(builder.ToString(TagRenderMode.SelfClosing), actionName, routeValues, ajaxOptions);
            return link.ToHtmlString();
        }
    }
我认为:

@Ajax.ImageActionLink("../../Content/Images/button_add.png", "JobTasksNew", "TrackMyJob",new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "tmjDynamic" }))
这就是我在呈现页面时得到的结果

   <a data-ajax="true" data-ajax-method="GET" data-ajax-mode="replace" data-ajax-update="#tmjDynamic" href="/TrackMyJob/JobTasksNew?Length=10"><img alt="" src="../../Content/Images/button_add.png"></img></a>
微软有一个ajax.actionlink.Replace的例子,但我没有这个方法。 你能帮我得到正确的html字符串吗

提前谢谢。

请尝试以下操作:

public static class ImageActionLinkHelper {
        public static MvcHtmlString ImageActionLink(this AjaxHelper helper, string imageUrl, string actionName, object routeValues, AjaxOptions ajaxOptions) {
            var builder = new TagBuilder("img");
            builder.MergeAttribute("src", imageUrl);
            builder.MergeAttribute("alt", "");
            var link = helper.ActionLink("[replaceme]", actionName, routeValues, ajaxOptions);
            var html = link.ToHtmlString().Replace("[replaceme]", builder.ToString(TagRenderMode.SelfClosing));
            return new MvcHtmlString(html);
        }
    }