htmlAttributesを使用した場合Ajax.ActionLinkとの問題は、誤ったリンクをレンダリング
-
11-09-2019 - |
質問
誰もが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&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>
私はこれを行うと(NULLの代わりに新しい{})
<%= 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 { })%>
それはすべて動作します!
所属していません StackOverflow