有没有人知道在Ajax.ActionLink中使用htmlAttributes时呈现错误的查询字符串的任何问题?似乎如果我为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&Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&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>
当我这样做时(null而不是new {}):
<%= 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参数。感谢您的任何见解!
答案 0 :(得分:2)
您需要使用方法的正确重载。你正在使用的那个采用IDictionary,这就是它呈现原样的原因。
如果选择对象RouteValues和对象htmlAttributes如下:
<%= Ajax.ActionLink("Delete", "Delete", "Milestone", new { id = Model.Id },
new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "ModalDeleteContainer",
OnSuccess = "modalDelete" }, new { })%>
一切都会奏效!