ajax.Actionlink OnComplete 从未被调用

发布于 2024-11-27 18:03:12 字数 985 浏览 1 评论 0原文

我正在使用 @Ajax.ActionLink 删除一条记录:

@Ajax.ActionLink("Delete","DeleteRun",new {RunId = run.RunId},
                     new AjaxOptions() { Confirm = "Are you sure you want to delete this entry?",
                                        HttpMethod = "DELETE",
                                        OnComplete = string.Format("DeleteRunInTable({0});",run.RunId)

                     })

生成以下链接:

<a data-ajax="true" data-ajax-complete="DeleteRunInTable(11);" data-ajax-confirm="Are you sure you want to delete this entry?" data-ajax-method="DELETE" href="/Runs/Delete/11">Delete</a>

删除工作正常,但 OnComplete javascript 函数“DeleteRunInTable”从未被调用(我在 javascript 中放置了一个断点)。有人知道为什么吗?

这是 javascript 函数(作为外部文件包含):

    function DeleteRunInTable(RunId) {
       $("tr[data-runid=" + RunId).remove();
}

我已经检查了 chrome 开发人员工具以确保脚本加载正常,而且确实如此。我还确保包含了 jquery 和 jquery unobtrusive。

I am using @Ajax.ActionLink to delete a record:

@Ajax.ActionLink("Delete","DeleteRun",new {RunId = run.RunId},
                     new AjaxOptions() { Confirm = "Are you sure you want to delete this entry?",
                                        HttpMethod = "DELETE",
                                        OnComplete = string.Format("DeleteRunInTable({0});",run.RunId)

                     })

Which produces the following link:

<a data-ajax="true" data-ajax-complete="DeleteRunInTable(11);" data-ajax-confirm="Are you sure you want to delete this entry?" data-ajax-method="DELETE" href="/Runs/Delete/11">Delete</a>

The delete is working perfectly but the OnComplete javascript function "DeleteRunInTable" is never called (i put a breakpoint in the javascript). Anyone know why?

Here is the javascript function (included as an external file):

    function DeleteRunInTable(RunId) {
       $("tr[data-runid=" + RunId).remove();
}

I've checked in chrome developer tools to make sure the script is loading ok and it is. I also made sure jquery and jquery unobtrusive were being included.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断舍离 2024-12-04 18:03:12

谢谢我让它工作了。我稍微改变了这个函数:

function DeleteRunInTable(RunId) {
    //$("tr[data-runid=" + RunId).remove();
    $("tr[data-runid='" + String(RunId) + "']").remove();
    return false;
}

不知道为什么它之前没有在断点处停止,但现在它工作正常。

Thanks i got it working. I changed the function a little:

function DeleteRunInTable(RunId) {
    //$("tr[data-runid=" + RunId).remove();
    $("tr[data-runid='" + String(RunId) + "']").remove();
    return false;
}

Don't know why it wasn't stopping at the break point before but now its working fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文