mvc ajax.actionlink 与 jquery 对话框确认
我有一个包含一些数据项行的表。对于每一行,都会有一些操作链接,它们将调用一些方法(删除数据项、更改状态数据项等...)
在每个用户单击按钮之前,我希望显示一个 jquery 对话框,并为用户提供一个包含一些信息的对话框,确定和取消按钮。
ajax.actionlink 的一些示例代码将调用 ChangeStatus 方法:
<%= Ajax.ActionLink(item.Status, "ChangeStatus", new { id = item.Id }, new AjaxOptions { UpdateTargetId = "ListReturns-Div", OnBegin = "StartChangeStatus", OnSuccess = "EndChangeStatus", OnFailure = "FailureChangeStatus" }, new { @class = "StatusBtn" })%>
这是调用的 jquery 函数:
function StartChangeStatus(e) {
$('#dialog-confirm').dialog({
resizable: false,
height: 200,
modal: true,
buttons: {
'Continue': function () {
$(this).dialog('close');
$('#Loading-Div').show('slow');
},
Cancel: function () {
$(this).dialog('close');
e.preventDefault();
}
}
});
}
actionlink 和 jquery 函数起作用。但问题是,单击操作链接时我无法暂停/停止当前操作。现在单击该按钮时,孔进程正在运行,并且对话框确认按钮将被忽略。所以我的问题是如何更改 actionlink 或 jquery 函数以在继续之前通过对话框确认按需要工作?
I have a table with some rows of data items. For each row it will be some actionlinks that will call some methods (delete dataitem, change status dataitem etc...)
Before each user clicks the button i want a jquery dialog to show up and give the user a dialog with some info, a OK and Cancel button.
Some example code of the ajax.actionlink that will call the ChangeStatus method:
<%= Ajax.ActionLink(item.Status, "ChangeStatus", new { id = item.Id }, new AjaxOptions { UpdateTargetId = "ListReturns-Div", OnBegin = "StartChangeStatus", OnSuccess = "EndChangeStatus", OnFailure = "FailureChangeStatus" }, new { @class = "StatusBtn" })%>
This is the jquery function that is called:
function StartChangeStatus(e) {
$('#dialog-confirm').dialog({
resizable: false,
height: 200,
modal: true,
buttons: {
'Continue': function () {
$(this).dialog('close');
$('#Loading-Div').show('slow');
},
Cancel: function () {
$(this).dialog('close');
e.preventDefault();
}
}
});
}
The actionlink and jquery functions work. But the problem is that i cannot pause/stop the current action when the actionlink is clicked. When the button is clicked now the hole process is running and the dialog confirm button is ignored. So my question is how to change the actionlink or the jquery function to work as wanted with a dialog confirmation before proceeding?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也尝试过你的代码,得到相同的行为。我已修改您的代码以显示确认框。
它正在显示 javascript 确认。需要找到它不起作用的原因。
I have also tried your code, getting the same behavior. I have modified your code to display confirm box.
and it is displaying the javascript confirm. Need to find the reason why it is not working.
来自我的网站:
现在,Ajax.ActionLink 真的很有用,并且Confirm AjaxOption更重要的是……现在谁想要那些蹩脚的 Javascript Alert?
我正在使用 Ms MVC 2 开发一个应用程序,并且使用出色的 JQueryUI 库来自定义所有元素的视觉效果。 JQueryUI 拥有的最好的功能之一是对话框窗口...诸如“您确定要删除此文件吗?是/否”之类的窗口...并且我想在我的 Ajax.ActionLink 中使用它们!
由于我在网上没有找到答案,所以我寻找一种简单的方法来做到这一点......现在我将其发布在这里。
首先:阅读并在您的页面上实现 Ricardo Covo 编写的精彩教程:“ASP MVC 使用 Ajax 和 jQuery UI 对话框删除确认”(只需 google 即可)
我对他的 Javascript 代码进行了简单的更改,只需使用remove() 而不是hide('fast') 并将类“item”应用于要删除的 tr。
现在
,在您按照上一教程进行操作后,您就可以将行替换
为
您可以使用 Post 方法(如果您愿意),这里重要的是 OnBegin 选项,它调用一个 javascript 来阻止调用服务器操作前
JQueryUI 对话框确认:
将 javascript 放置在页面上。
那么,现在会发生什么:当您单击“删除”按钮时,它将打开 JQueryUI,同时调用 OnBegin 函数(取消正常的后操作)。如果是“确认”,Ricardo Covo 的代码将触发服务器端操作,并且在 Ricardo Covo 的确认 javascript 代码中,您将能够执行成功时的所有操作(例如隐藏行删除)。
注意:使用此方法,您必须在 Ricardo Covo 的 javascript 代码中管理成功/失败的函数,因为 OnSuccess 和 OnComplete AjaxOptions 根本不会被触发(可能被某些代码覆盖)。
From my website:
Now, Ajax.ActionLink is really useful, and the Confirm AjaxOption is even more...still, who wants those crappy Javascript Alert these days?
I am developing an application with Ms MVC 2 and I'm using the fantastic JQueryUI library to customize the visuals of all my elements. One of the best things JQueryUI has, are dialog windows...those like "Are you sure to delete this file? Yes/No"... and I WANT TO USE THEM IN MY Ajax.ActionLink!
Since i didn't find an answer on the net, I looked for a simple way to do it...and now I post it here.
First: read and implement on your page the nice tutorial written by Ricardo Covo: "ASP MVC Delete confirmation with Ajax & jQuery UI Dialog" (Just google it)
I made simple changes to his Javascript code, simply using remove() instead of hide('fast') and applying a class "item" to the tr to delete.
becomes
Now, after you followed the previous tutorial, you are ready to substitute the
row with
You can use the Post method if you like to, the important thing here is the OnBegin option, that calls a javascript that prevents the server action to be called before
JQueryUI Dialog Confirmation:
Place the javascript on the page.
So, now what will happens: When you click on the Delete button, it will open the JQueryUI whilst calling the OnBegin function (that cancel the normal post action). In case of "Confirm", Ricardo Covo's code will fire the server side action, and in the Ricardo Covo's javascript code of Confirmation you'll be able to execute all the actions in case of Success (like hiding the row delete).
Pay Attention: With this method, you must manage function for success/fail in the javascript code of Ricardo Covo, since the OnSuccess and OnComplete AjaxOptions will not be fired at all (probably overwritten by some code).