Avoiding Duplicate form submission in Asp.net MVC by clicking submit twice

前端 未结 6 1681
情书的邮戳
情书的邮戳 2021-01-30 22:30

I am rendering a form in Asp.net MVC with a submit button. The page redirects after successful record addition into the database. Following is the code :-

[HttpP         


        
6条回答
  •  情歌与酒
    2021-01-30 22:50

    You can use this one. It includes unobtrusive jQuery validation.

    $(document).on('submit', 'form', function () {
        var buttons = $(this).find('[type="submit"]');
        if ($(this).valid()) {
            buttons.each(function (btn) {
                $(buttons[btn]).prop('disabled', true);
            });
        } else {
            buttons.each(function (btn) {
                $(buttons[btn]).prop('disabled', false);
            });
        } });
    

    For jQuery validation please incllude

    ~/Scripts/jquery.validate.min.js
    ~/Scripts/jquery.validate.unobtrusive.min.js
    

提交回复
热议问题