2009-04-17 15 views
0

Ajax.ActionLinkでhtmlAttributesを使用しているときに誤ったクエリーストリングがレンダリングされる問題を知っている人はいますか? htmlAttributesに空の配列を入れても、リンクが正しくレンダリングされないようです。ここに私のコードです。htmlAttributesを使用しているときにAjax.ActionLinkでリンクが正しく表示されない問題

私はこれを行うと(新しい{}注):

<%= 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&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> 

私はこれを行う場合(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引数です。どんな洞察もありがとう!

答えて

2

メソッドの正しいオーバーロードを使用する必要があります。あなたが使用しているものはIDictionaryをとるので、それがそのままレンダリングされています。

あなたは、このようなオブジェクトのRouteValuesとオブジェクトhtmlAttributesを選択した場合:

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

それはすべて動作します!

+0

素晴らしいです。ありがとう! –

関連する問題