Learn to use Multiple Submit Button and Forms in MVC

1
5577
multiple-forms-in-single-view-in-MVC-2

multiple-forms-in-single-view-in-MVC-2

Sometime we need multiple submit button/multiple forms on a single form in MVC razor, in that scenario how will we handle the click event?
In this article, we will learn different ways of handling multiple submit button on the same view.
1

In the above diagram. We have Save & Submit buttons. Suppose when you click on Save button, you have to save data in the temp table & on Submit button you have to save the data in main table. For handling the above scenario, we have different ways to perform task:

Method 1
In this method, each submit button will post the form to the server but provides the different values – Save and Submit respectively for the commands. On the basis of command name we can implement our own logic in the controller’s action method.

View with multiple submit:

2

Action method on controller:

3

Learn HTML5 Programming For Beginners

Method 2
In this method, we introduce a new form for handling the submit button click event. We can also use action method.

View with multiple submit & multiple form:

4

Action method on controller:

5

I hope you will enjoy these tricks when coding with MVC Razor.

Summary: In above example we have learnt how to use multiple submit and forms in single view in MVC.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here