asp.net-mvc-3 – ASP.NET MVC – 扩展Ajax.ActionLink方法
发布时间:2020-12-16 06:24:06 所属栏目:asp.Net 来源:网络整理
导读:有没有我可以看到当前Ajax.ActionLink方法的方法定义,因为我希望能够使用自定义方法扩展它,但不确定其当前的方法定义 编辑:这是我到目前为止: public static class AjaxExtensions { public static IHtmlString MyActionLink( this AjaxHelper htmlHelper,
有没有我可以看到当前Ajax.ActionLink方法的方法定义,因为我希望能够使用自定义方法扩展它,但不确定其当前的方法定义
编辑:这是我到目前为止: public static class AjaxExtensions { public static IHtmlString MyActionLink( this AjaxHelper htmlHelper,string linkText,string action,string controller,object routeValues,AjaxOptions ajaxoptions,object htmlAttributes ) { var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext); var anchor = new TagBuilder("a"); anchor.InnerHtml = linkText; anchor.Attributes["href"] = urlHelper.Action(action,controller,routeValues); anchor.MergeAttributes(new RouteValueDictionary(htmlAttributes)); return MvcHtmlString.Create(anchor.ToString()); } } 但显然我需要添加默认Ajax.ActionLink包含的AjaxOptions内容,但我不确定它的定义是什么样的. 这样做的原因是我希望linkText是一个HtmlString,因为我想这样做:@ Ajax.MyActionLink(“< span class =”highlight“> Hello< / span> World”,.. .) 第二编辑: 我现在收到编译错误: ...does not contain a definition for 'MyActionLink' and the best extension method overload 'MyProject.Helpers.AjaxExtensions.MyActionLink(System.Web.Mvc.AjaxHelper,System.Web.HtmlString,string,object,System.Web.Mvc.Ajax.AjaxOptions)' has some invalid arguments 这是我的扩展方法: public static IHtmlString MyActionLink( this AjaxHelper ajaxHelper,HtmlString linkText,AjaxOptions ajaxoptions ) { return MyActionLink(ajaxHelper,linkText,action,routeValues,ajaxoptions); } 这是我如何使用它: @Ajax.MyActionLink(@Html.Raw(item.ITEMID.Replace((string)ViewData["ID"],"<span class='highlighted'>" + (string)ViewData["ID"] + "</span>")),"MoreDetails",new { id = item.ITEMID },new AjaxOptions() { UpdateTargetId = "MoreDetails-" + item.ITEMID,InsertionMode = InsertionMode.Replace }) 第三编辑: 我改变了我的扩展方法: public static IHtmlString MyActionLink( this AjaxHelper ajaxHelper,IHtmlString linkText,AjaxOptions ajaxoptions ) { return MyActionLink(ajaxHelper,ajaxoptions); } 现在我收到以下错误: Cannot evaluate expression because the current thread is in a stack overflow state. System.Collections.IDictionary 解决方法
我通过使用此处找到的解决方案解决了它:
http://forums.asp.net/p/1702210/4518688.aspx/1?Re+Quick+question+about+Ajax+ActionLink+and+span
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 用于DropDownList的MVC2 EditorTemplate
- asp.net-mvc – ASP.NET MVC – 与使用模型注释相比,使用自
- asp.net – 如何知道为什么IIS应用程序池被回收
- asp.net – web.config和app.config混淆
- asp.net-mvc – Glass Mapper Unity
- asp-classic – 如何在Classic ASP中创建变量static(或“gl
- asp.net – 使用Active Directory的REST API的授权方法
- asp.net:控件/页面的页面生命周期顺序与其中的用户contorl
- asp.net – asp .net mvc 4下拉列表
- [你必须知道的.NET] 第六回:深入浅出关键字---base和this
推荐文章
站长推荐
热点阅读