有谁知道,在一个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&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参数。感谢您的见解!

有帮助吗?

解决方案

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

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

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

它将所有的工作!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top