2010-09-14 73 views
1

当我得到这个ActionLink的是在Firefox丢失)后的参数列表错误使用Ajax.ActionLink MVC2

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

这似乎是从的小JavaScript片段我来产生这个错误。我虽然逃过了报价,所以我很难过。

回答

2

我在这里看到的是,您正在使用jQuery和Microsoft AJAX。这两个没有理由在同一个项目中混合使用,如果你已经有了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; 
    }); 
}); 
1

你必须通过一个函数的名称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"); 
} 
相关问题