Show loader on Ajax.BeginForm submit

后端 未结 1 802
萌比男神i
萌比男神i 2021-02-20 04:25

What is the best way to show a loader and disable the button when we submit a form:

@using (Ajax.BeginForm(MVC.Account.Login(), new AjaxOptions { OnSuccess = \"o         


        
相关标签:
1条回答
  • 2021-02-20 04:37

    Put your loading image tag inside a div tag like this:

    <div id="loading">
        <img src="~/Content/Images/ui-loader-white-16x16.gif" />
    </div>
    

    In your CSS file:

    div#loading { display: none; }
    

    And, in your form:

    @using (Ajax.BeginForm(MVC.Account.Login(), 
      new AjaxOptions { OnSuccess = "onLoginSuccess", LoadingElementId = "loading", 
        OnBegin = "onLoginBegin" }, 
      new { @id = "loginForm" }))
    {
      <div id="logbtn">
        <input type="submit" name="invisible" class="subinvisible"/> 
        <p>@HeelpResources.AccountLoginViewLoginButtonLabel</p>
        <img src="~/Content/Images/ui-symb-arrow-right-white-15x15.png" width="13" height="12" />
      </div>
    }
    

    And, add a script to your View:

    <script type="text/javascript">
        function onLoginBegin()
        { 
            // Disable the button and hide the other image here 
            // or you can hide the whole div like below
            $('#logbtn').hide();
        }
    </script>
    
    0 讨论(0)
提交回复
热议问题