【问题标题】:Issue with Ajax.ActionLink incorrectly rendering links when using htmlAttributes使用 htmlAttributes 时 Ajax.ActionLink 的问题会错误地呈现链接
【发布时间】:2009-04-18 01:50:35
【问题描述】:

有谁知道在 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&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 而不是 new { }):

<%= 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 参数。感谢您的任何见解!

【问题讨论】:

    标签: asp.net-mvc ajax rendering actionlink


    【解决方案1】:

    您需要使用正确的方法重载。您正在使用的那个需要一个 IDictionary,这就是它呈现它的方式的原因。

    如果你像这样选择对象 RouteValues 和对象 htmlAttributes:

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

    一切都会好起来的!

    【讨论】:

      猜你喜欢
      • 2020-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-25
      • 1970-01-01
      • 1970-01-01
      • 2015-07-02
      • 1970-01-01
      相关资源
      最近更新 更多