Vitaliy Vitaliy - 6 months ago 29
jQuery Question

block button on submit form

Trying to avoid multiple submission on submit button click using attribute

, but on click it just block the button and nothing happens. Have tried to add
to Html.Begin form, but on click it gives server application error like :
the parameters dictionary contains a null entry for parameter 'id' of non-nullable type System.Int32

@using (Html.BeginForm(MVC.Controller.MethodName(), FormMethod.Post, new { id = "submitFormId" }))

<button class="btn btn-w-m btn-primary" type="button" id="submitButtonId" value="AddSmth" onclick="return validateForm(event)">
<i class="fa fa-plus"></i>&nbsp;Add

And js:



Founded another way to prevent multiple click on the button. Just added :

@{ Html.EnableClientValidation(); }
@{ Html.EnableUnobtrusiveJavaScript(); }

To the view, and after added global variable var isSubmited = false;, then validating it by:

if (isSubmited) e.PreventDefault();

. . .

if ($('#submitFormId').valid()) {
            isSubmited = true;