Button type “button” vs. “submit”

前端 未结 6 1864
北荒
北荒 2020-11-30 06:04

Is there a difference between a button with type=\"button\" vs type=\"submit\"? Are there functional differences, or is it just a desc

6条回答
  •  借酒劲吻你
    2020-11-30 06:19

     
    

    buttons will not submit a form - they don't do anything by default. They're generally used in conjunction with JavaScript as part of an AJAX application.

     
    

    buttons will submit the form they are in when the user clicks on them, unless you specify otherwise with JavaScript.

    when form submit by below code, We should use type=button instead of type=submit to prevent form submit twice.

    @using (Html.BeginForm("View", "Controller", FormMethod.Post, new { id = "signupform" }))
            {
             //Form elements
            }
    

提交回复
热议问题