ASP.NET JQuery, disabled a button on form submit not call httpPost action

bateye

I'm working in an ASP.NET MVC app and I want to disable a button when during OnSubmit event of the form, just for prevent double click of the users. All JQuery part is working fine but I don't understand why, when I disabled the submit button, it always call the default Action of my controller.

Here is the cshtml code:

@using(Html.BeginForm()){
  <input type="submit" value="Submit"/>
}
<script>
$(function(){
  $("form").submit(e=>{
    $('input[type="submit"]').prop("disable",true)
  })
})
</script>

The JQuery part works and make the button disabled.

My controller:

public class MyController:Controller{
  public ActionResult MyController(ExampleModel model){
    return View(model);
  }
  [HttpPost,ActionName("MyController")]
  public ActionResult FormSubmmit(ExampleModel model){
    //Do some checks
    return View(model);
  }
}

The case is that if I make the button disabled, the form always call the action 'MyController' instead of the action FormSubmit (is which I want to call). Do somebody know why can be the reason of this "error"?

bateye

Firstable, thank for answer! And I just find the solution.

The problem of the code was if I use disabled it change the request metadata during the form submit event, so I can not make the button disabled.

I fount this solution, it just take off the pointer events from the button and then it prevent the double submit problem.

$('input[type="submit"]').css("pointer-events","none")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

disabled button after submit form with model validation asp.net core

ASP.NET Button click call Javascript function in BeginForm and stop form submit

How to call asp.net mvc form submit event which use ajax after button click and validate?

How to submit formdata to ASP.NET Core MVC action using JQuery Ajax in a dynamic created form

NET CORE 3.1 MVC HttpPost Controller action gets a NULL parameter on form submit in view

Submit form after successful ajax call using jQuery in asp.net mvc 5

How to call MVC Action using Jquery AJAX and then submit form in MVC?

Disabled submit button if form is invalid angularjs

Submit form on Radio Button click in ASP.Net Core

ASP.NET Prevent Form Validation with HTML 5 Submit Button

Server returns 405 error when ASP.NET CORE 3.1 Action with HttpPost called from Html Form

jQuery Custom Plugin for submit button disabled/enabled

Call Action Method on button click ASP.NET MVC

ASP.NET MVC AJAX Form Submit losing ListBoxFor/MultiSelectList on submit/post action

Hitting button outside a form to call submit on Submit button in a form

ASP.Net MVC, submit form with JQuery.Ajax

Jquery ui Submit form ajax asp.net

Unable to submit form with a jquery button

JQuery validation form but not `submit` button

Enabling a disabled form button after submit & browser back button

Select submit button after form submit in jQuery

How to attach an action call to a submit button in Rails?

Submit button cannot trigger to run form action

Change Simple_Form Submit Button Action?

How can i submit my form using the submit button in a modal? (ASP.NET MVC)

Form submit button stays disabled after ajax post

Disabled submit button, but valid form data will not enable it (vee-validate)

html button stay in disabled status after a form submit

Angular, Disable submit button using [disabled] to check form validity