使用Ajax.ActionLink MVC2时,参数列表错误后失踪)错误、参数、列表、Ajax

由网友(遍体鳞伤够不够美)分享简介:我这有ActionLink的是产生在Firefox这个错误I've got this actionlink that is generating this error in firefox<%: Ajax.ActionLink(" ", "SelectEditProduct", new { id = item.Id...

我这有ActionLink的是产生在Firefox这个错误

I've got this actionlink that is generating this error in firefox

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

这似乎是从一些JavaScript代码片段我来了。我躲过了报价,但这样我很为难。

It seems to be coming from the little javascript snippet I have. I escaped the quotations though so I'm stumped.

推荐答案

我在这里看到的是,你正在使用jQuery一起使用Microsoft AJAX。这两个有什么理由在同一个项目中混合,如果你已经有jQuery的另一种是完全无用的。因此,而不是污染您的标记使用javascript,不知道如何逃避单引号和双引号用斜杠,并获得大量的错误的,这样做不显眼(jQuery的方式):

What I see here is that you are using jQuery alongside with Microsoft AJAX. Those two have no reason to be mixed in the same project and if you already have jQuery the other is completely useless. So instead of polluting your markup with javascript and wondering how to escape single and double quotes with slashes and get plenty of errors, do it unobtrusively (the jQuery way):

<%: 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;
    });
});
阅读全文

相关推荐

最新文章