Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

What is the 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).

like image 809
Beep beep Avatar asked Dec 12 '22 13:12

Beep beep


1 Answers

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

$(function() {
    $('form').submit(function() {
        $(':submit, :image', this).attr('disabled', 'disabled');
    });
});
like image 88
Darin Dimitrov Avatar answered May 12 '23 06:05

Darin Dimitrov