开发者

Preventing action in web application from being called twice (ASP.NET MVC)

What is 开发者_如何学Cthe best way to make sure an ASP.NET MVC action is not called twice (i.e. if the user clicks on a button twice in quick succession)? On most of our screens, it's not a big deal if it happens ... but on a few it causes havoc (like paying people multiple times instead of just once).


You could disable the submit button using javascript. For example with jQuery:

$(function() {
    $('form').submit(function() {
        $(':submit, :image', this).attr('disabled', 'disabled');
    });
});


There was a recent thread about this (with Darin actually).

A combination of doing as he mentioned and implementing a Post-Redirect-Get strategy covers most holes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜