Problema con Ajax.ActionLink in modo non corretto rendering link quando si utilizza htmlAttributes

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

Domanda

Qualcuno sa di eventuali problemi con il rendering corretto querystrings quando si utilizza htmlAttributes in Ajax.ActionLink?Sembra che se ho messo anche un array vuoto per il htmlAttributes, il collegamento viene visualizzato in modo non corretto.Ecco il mio codice.

Quando faccio questo (notare il nuovo { }):

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

Il collegamento rende simile a questo:

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

Quando faccio questo (null invece di nuovo { }):

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

Il collegamento rende simile a questo:

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

L'unica differenza tra i due è il htmlAttributes argomento alla fine dell'Ajax.ActionLink.Grazie per la comprensione!

È stato utile?

Soluzione

È necessario utilizzare la corretta overload del metodo.L'utilizzo richiede un IDictionary e che è il motivo per cui rendering è così.

Se si sceglie l'oggetto RouteValues e oggetto htmlAttributes come questo:

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

tutto funzionerà!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top