Asp.net mvc 在自定义ajaxhelper中合并ajax选项

Asp.net mvc 在自定义ajaxhelper中合并ajax选项,asp.net-mvc,asp.net-mvc-2,Asp.net Mvc,Asp.net Mvc 2,如何合并此自定义扩展方法中的选项 public static MvcHtmlString ActionLink(this AjaxHelper html, string linkText, string actionName, object htmlAttributes, AjaxOpt

如何合并此自定义扩展方法中的选项

  public static MvcHtmlString ActionLink(this AjaxHelper html,
                    string linkText,
                    string actionName,                        
                    object htmlAttributes,
                    AjaxOptions options )
    {
        RouteValueDictionary attributes = new RouteValueDictionary(htmlAttributes);


        TagBuilder linkTag = new TagBuilder("a");        

        UrlHelper url = new UrlHelper(html.ViewContext.RequestContext);

        linkTag.Attributes.Add("href", url.Action(actionName));



        return MvcHtmlString.Create(linkTag.ToString(TagRenderMode.Normal));
    }
}

AjaxOptions只是一个类。您可以在其上设置自己的属性。我建议使用现有的Ajax帮助程序,并首先更改AjaxOption。因此:

public static MvcHtmlString ActionLinkWithSpan(this AjaxHelper html,
                        string linkText,
                        string actionName,
                        object htmlAttributes,
                        AjaxOptions options)
{
    RouteValueDictionary attributes = new RouteValueDictionary(htmlAttributes);
    // Add more attributes here if you want

    options.InsertionMode = InsertionMode.InsertBefore; // As an example. Or amend any others here.

    return html.ActionLink(linkText, actionName, attributes, options);
}

您可以将
AjaxOptions
合并到链接标记,如下所示:

linkTag.MergeAttributes(ajaxOptions.ToUnobtrusiveHtmlAttributes());
此外,您可以将html属性合并为

linkTag.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));

你还没有说清楚你想要实现什么。你延期的目的是什么?跨度从何而来?我正在编写一个生成自定义actionlink的方法。span只是一个名字忽略它