Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent multiple POST in asp.net mvc application

How do I prevent the user from posting the same data to the action multiple times if they keep clicking the submit button?

I know in php, there is a way to prevent this multiple submission, but I do not see any for asp.net mvc. Is there any?

like image 423
Shawn Mclean Avatar asked Dec 17 '22 14:12

Shawn Mclean


1 Answers

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

$(function() {
    $('form').submit(function() {
        $('#idofsubmitbutton').attr('disabled', 'disabled');
    });
});

Note however that this might not be 100% reliable as for example the user could have javascript disabled or even worse: he could have malicious intents and automate HTTP POST requests.

like image 51
Darin Dimitrov Avatar answered Jan 06 '23 01:01

Darin Dimitrov