user2443194 user2443194 - 2 years ago 74
Javascript Question

Creating button not calling any action inside form

Is there any way to create a button inside html form that wouldn't call an action specified in "Html.BeginForm"? I want to use it only for adding some elements to form by javascript. I have a different button that should call an action.

@using (Html.BeginForm...
<button id="addRow" class="btn margin-top-10 margin-bottom-10">addRowt</button>

The "addRow" button I'd like not to call any action.

Thanks in advance

Answer Source

Yes. You can listen to the click event of this button and prevent the default behavior. Assuming you ave jQuery library loaded in this page, you may use jquery preventDefault method to do this.


     // do other things as needed (ex : add a row to ui)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download