mvc4.0 html.actionlink comfired,asp.net mvc - mvc ajax.actionlink with jquery dialog confirm - Stack...

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.

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:

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).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值