2009-04-17 31 views
0

有没有人知道在Ajax.ActionLink中使用htmlAttributes时渲染不正确的查询字符串的问题?看来,如果我甚至为htmlAttributes放入一个空数组,链接也会呈现错误。这是我的代码。Ajax.ActionLink问题在使用htmlAttributes时错误地呈现链接

当我这样做(注意新{}):

<%= Ajax.ActionLink("Delete", "Delete", "Milestone", new RouteValueDictionary { { "id", Model.Id } }, new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "ModalDeleteContainer", OnSuccess = "modalDelete" }, new { })%> 

链接呈现这样的:

<a href="/Client/1/Admin/Milestone/Delete?Count=1&amp;Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&amp;Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, httpMethod: 'GET', updateTargetId: 'ModalDeleteContainer', onSuccess: Function.createDelegate(this, modalDelete) });">Delete</a> 

当我做到这一点(的空,而不是新的{}):

<%= Ajax.ActionLink("Delete", "Delete", "Milestone", new RouteValueDictionary { { "id", Model.Id } }, new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "ModalDeleteContainer", OnSuccess = "modalDelete" }, null)%> 

链接呈现这样的:

<a href="/Client/1/Admin/Milestone/Delete/703c749e-c145-4cf1-90eb-9bee00bac79d" onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, httpMethod: 'GET', updateTargetId: 'ModalDeleteContainer', onSuccess: Function.createDelegate(this, modalDelete) });">Delete</a> 

两者的唯一区别是Ajax.ActionLink末尾的htmlAttributes参数。感谢您的任何见解!

回答

2

您需要使用方法的正确过载。你使用的是一个IDictionary,这就是为什么它正在渲染它。

如果你选择的对象RouteValues和对象htmlAttributes这样的:

<%= Ajax.ActionLink("Delete", "Delete", "Milestone", new { id = Model.Id }, 
new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "ModalDeleteContainer", 
OnSuccess = "modalDelete" }, new { })%> 

它将所有的工作!

+0

真棒,这工作!谢谢! – 2009-04-17 17:52:01

相关问题