Problème avec Ajax.ActionLink qui ne rend pas correctement les liens lors de l'utilisation de htmlAttributes

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

Question

Quelqu'un connaît-il des problèmes liés au rendu de chaînes de requête incorrectes lors de l'utilisation de htmlAttributes dans un Ajax.ActionLink ?Il semble que si je mets même un tableau vide pour les htmlAttributes, le lien n'est pas rendu correctement.Voici mon code.

Quand je fais cela (notez le nouveau { }) :

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

Le lien s'affiche comme ceci :

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

Quand je fais cela (null au lieu de new { }) :

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

Le lien s'affiche comme ceci :

<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 seule différence entre les deux est l'argument htmlAttributes à la fin d'Ajax.ActionLink.Merci pour tout aperçu!

Était-ce utile?

La solution

Vous devez utiliser la surcharge correcte de la méthode.Celui que vous utilisez prend un IDictionary et c'est pourquoi il s'affiche tel qu'il est.

Si vous choisissez l'objet RouteValues ​​et l'objet htmlAttributes comme ceci :

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

tout fonctionnera !

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top