2
从我的网站:
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!
现在,Ajax。ActionLink非常有用,而Confirm AjaxOption甚至更……不过,谁还想要这些糟糕的Javascript警告呢?我正在用Ms MVC 2开发一个应用程序,我正在使用出色的JQueryUI库来定制我所有元素的可视化。JQueryUI最好的功能之一是对话窗口……比如“你确定要删除这个文件吗?”是/否”……我想在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)
首先:在你的页面上阅读并实现Ricardo Covo编写的精美教程:“使用Ajax和jQuery UI对话框进行ASP MVC删除确认”(只需谷歌)
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.
我对他的Javascript代码做了简单的修改,只是使用remove()而不是hide('fast),并向tr应用一个类“item”来删除。
deleteLinkObj.closest("tr").hide('fast')
becomes
就变成了
deleteLinkObj.closest("tr.item").remove();
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:
如果您愿意,可以使用Post方法,这里重要的是OnBegin选项,它调用一个javascript来防止在JQueryUI对话框确认之前调用服务器操作:
Place the javascript on the page.
将javascript放在页面上。
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).
因此,现在会发生什么:当您单击Delete按钮时,它将在调用OnBegin函数时打开JQueryUI(取消常规post操作)。在“确认”的情况下,Ricardo Covo的代码将触发服务器端操作,在Ricardo Covo的javascript确认代码中,您将能够在成功的情况下执行所有操作(如隐藏行删除)。
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).
注意:使用此方法,您必须管理Ricardo Covo的javascript代码中的success/fail函数,因为不会触发OnSuccess和OnComplete AjaxOptions(可能被某些代码覆盖)。