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

前端 未结 6 1692
情书的邮戳
情书的邮戳 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 ajax.BeginForm insted of html.BeginForm to achieve this, if you use OnSuccess insted of OnBegin you can be sure that your method execute successful and after that your button turn to deactivate,with ajax you stay in current view and you can update your current view instead of redirection

    @using (Ajax.BeginForm(
    new AjaxOptions
    {
        HttpMethod = "post",
        InsertionMode = InsertionMode.Replace,
        UpdateTargetId = "dive",
        OnBegin="deactive"
    }))
    {
    //body of your form same as Html.BeginForm
    
    }
    

    and use this jquery in your form:

    
    

    be careful for using ajax you have to call this scrip in the end of your page

    
    

提交回复
热议问题