代码之家  ›  专栏  ›  技术社区  ›  Grahame A

使用时参数列表错误后缺少)Ajax.ActionLinkmvc2型

  •  1
  • Grahame A  · 技术社区  · 16 年前

    我有一个actionlink在firefox中生成了这个错误

    <%: Ajax.ActionLink(" ", "SelectEditProduct", new { id = item.Id }, new AjaxOptions { UpdateTargetId = "dialog", InsertionMode = InsertionMode.Replace, OnSuccess = "$(\"#dialog\").dialog(\"open\");"}, new { Class="edit"})%>
    

    它似乎来自我的小javascript片段。不过,我漏掉了引文,所以我被难住了。

    2 回复  |  直到 16 年前
        1
  •  2
  •   Darin Dimitrov    16 年前

    我在这里看到的是,您将jQuery与microsoftajax一起使用。这两者没有理由混合在同一个项目中,如果您已经有jQuery,那么另一个就完全没有用了。因此,与其用javascript污染标记,不想知道如何用斜杠转义单引号和双引号,从而得到大量错误,不如低调地进行(jQuery方式):

    <%: Html.ActionLink(
        "Some link text", 
        "SelectEditProduct", 
        new { id = item.Id }, 
        new { @class = "edit" }
    ) %>
    

    在一个 js文件:

    $(function() {
        $('a.edit').click(function() {
            // When a link with class="edit" is clicked
            // send an AJAX request to the href and replace the result
            // of a DOM element with id="dialog" with the response
            // returned by the server
            // Also when the request completes show a jQuery dialog.
            $('#dialog').load(this.href, function() {
                $('#dialog').dialog('open');
            });
            return false;
        });
    });
    
        2
  •  1
  •   davehauser    16 年前

    必须将函数名传递给 OnSuccess ,不能在AjaxOptions中正确编写函数。因此,请将代码更改为:

    <%: Ajax.ActionLink(" ", "SelectEditProduct", new { id = item.Id }, new AjaxOptions { UpdateTargetId = "dialog", InsertionMode = InsertionMode.Replace, OnSuccess = "openDialog"}, new { Class="edit"})%>
    

    然后编写相应的JavaScript函数:

    openDialog = function() {
        $("#dialog").dialog("open");
    }