Beep beep
Beep beep

Reputation: 19171

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

Upvotes: 4

Views: 523

Answers (2)

Khepri
Khepri

Reputation: 9627

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.

Upvotes: 6

Darin Dimitrov
Darin Dimitrov

Reputation: 1039498

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

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

Upvotes: 7

Related Questions