skip to Main Content

I have a controller in c# and inside the controller there is a save method. The save method saves/updates data that is submitted by submit button click and javascript. The problem is, if you click on the button multiple time, it should only process the very first click and rest of them should be identified as duplicate submit and should be discarded by controller. How to do this in c# mvc web application?

3

Answers


  1. Disable the button after it’s clicked. So it can just be clicked once.

    Login or Signup to reply.
  2. Simple way

    • when button clicked disabled it then actived again after you got response result from ajax! u can also add loader that make ur web look so cool!
    <button id="btnSend" onClick="send()">submit</button>
    
    <script>
    
    btnSend=document.getElementById("btnSend");
    
    function send(){
    
      btnSend.disabled=true;
      //set disabled button here
    
      $.ajax({ type: "GET",   
               url: "http://www.google.de",   
               async: false,
               success : function(text)
               {
                    btnSend.disabled=false;
                    //set active to button 
                    
                    // add your code here
               },
    
               fail : function(text)
               {
                    btnSend.disabled=false;
                    //set active to button 
    
                    // add your code here
               }
      });
    
    }
    
    </script>
    
    
    
    Login or Signup to reply.
  3. I would also disable the button on the client side. But you could also check if the submitted data is different from the stored data. If no changes were made you could just return without further saving logic.

    Should it be possible to just save the data once? Maybe a redirect to a different view after saving could be a possible solution in special cases.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search