Problema con Ajax.ActionLink que muestra enlaces incorrectamente cuando se utilizan htmlAttributes

StackOverflow https://stackoverflow.com/questions/761288

Pregunta

¿Alguien sabe de algún problema con la representación de cadenas de consulta incorrectas cuando se utilizan htmlAttributes en un Ajax.ActionLink?Parece que si coloco incluso una matriz vacía para htmlAttributes, el enlace se representa incorrectamente.Aquí está mi código.

Cuando hago esto (tenga en cuenta el nuevo {}):

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

El enlace se muestra así:

<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>

Cuando hago esto (nulo en lugar de nuevo {}):

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

El enlace se muestra así:

<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>

La única diferencia entre los dos es el argumento htmlAttributes al final de Ajax.ActionLink.¡Gracias por cualquier idea!

¿Fue útil?

Solución

Debe utilizar la sobrecarga correcta del método.El que estás usando toma un IDictionary y es por eso que se muestra como está.

Si elige el objeto RouteValues ​​y el objeto htmlAttributes como este:

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

¡todo funcionará!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top