Yazan
Yazan

Reputation: 71

How to prevent Action Post method called from Submit form Hit twice?

I have the following control in my .cshtml view:

<"a id="BtnSubmit" onclick="SubmitForm();"><img id="ImgSave" src="~/images/IcnSave.png" /></a>

    function SubmitForm() {
       $('#Form_Create_Edit_Customer_Contact_FollowUp').submit();
    }

Where #Form_Create_Edit_Customer_Contact_FollowUp is the name of the form.

The problem is that the corresponding controller POST method is being hit twice, how can I stop the current behaviour.

Note: I need to use a link rather than Button/Input with type submit for design reasons.

Upvotes: 0

Views: 163

Answers (1)

Vicky Kumar
Vicky Kumar

Reputation: 249

To avoid the current behaviour you can try below code

function SubmitForm(e) {
      e.preventDefault()
      $('#Form_Create_Edit_Customer_Contact_FollowUp').submit();
   }

Upvotes: 2

Related Questions