Ajax动作链接和css id

时间:2014-03-04 11:42:24

标签: asp.net ajax asp.net-mvc-4

ajax链接可正常运行,但添加此部分" new { @class = "delete" } "后,在成功后未调用DEL_row()。如果我删除此new { @class = "delete" }
然后将调用DEL_row()

代码如下:

  @Ajax.ActionLink(" ",
                 "DeleteConfirmed",
                   new RouteValueDictionary { { "id", item.chanID } },
                 new AjaxOptions
                 {

                     InsertionMode = InsertionMode.Replace,
                     HttpMethod = "GET",
                     OnSuccess = "DEl_row('" + item.chanID + "')"
                 }, new { @class = "delete" })

1 个答案:

答案 0 :(得分:0)

您正在尝试使用overload with the signature

AjaxExtensions.ActionLink Method (AjaxHelper, String, String, Object, AjaxOptions, Object)

因此您的RouteValueDictionary参数解释不正确,因此您需要使用匿名对象:

@Ajax.ActionLink(" ",
    "DeleteConfirmed",
    new { id = item.chanID },
    new AjaxOptions
    {
         InsertionMode = InsertionMode.Replace,
         HttpMethod = "GET",
         OnSuccess = "DEl_row('" + item.chanID + "')"
    }, new { @class = "delete" })

或者使用different overload,其中RouteValueDictionary和html属性为IDictionary<string, Object>

@Ajax.ActionLink(" ",
    "DeleteConfirmed",
    new RouteValueDictionary { { "id", item.chanID } },
    new AjaxOptions
    {
         InsertionMode = InsertionMode.Replace,
         HttpMethod = "GET",
         OnSuccess = "DEl_row('" + item.chanID + "')"
    }, new Dictionary<string, Object>{ { "class", "delete"} })