Problema com Ajax.ActionLink incorretamente tornando ligações ao usar htmlAttributes
-
11-09-2019 - |
Pergunta
Alguém sabe de quaisquer problemas com tornando querystrings incorretos quando usando htmlAttributes em uma Ajax.ActionLink? Parece que se eu colocar até mesmo uma matriz vazia no para os htmlAttributes, o link é renderizado incorretamente. Aqui está o meu código.
Quando faço isso (note o novo {}):
<%= Ajax.ActionLink("Delete", "Delete", "Milestone", new RouteValueDictionary { { "id", Model.Id } }, new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "ModalDeleteContainer", OnSuccess = "modalDelete" }, new { })%>
A ligação torna assim:
<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>
Quando faço isso (null em vez de novo {}):
<%= Ajax.ActionLink("Delete", "Delete", "Milestone", new RouteValueDictionary { { "id", Model.Id } }, new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "ModalDeleteContainer", OnSuccess = "modalDelete" }, null)%>
A ligação torna assim:
<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>
A única diferença entre os dois é o argumento htmlAttributes no final do Ajax.ActionLink. Obrigado por qualquer visão!
Solução
Você precisa usar a sobrecarga correto do método. O que você está usando tem um IDictionary e é por isso que é renderização do jeito que está.
Se você escolher as routeValues ??objeto e htmlAttributes objeto como este:
<%= Ajax.ActionLink("Delete", "Delete", "Milestone", new { id = Model.Id },
new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "ModalDeleteContainer",
OnSuccess = "modalDelete" }, new { })%>
tudo vai funcionar!