Home/MVC/How to handle Multiple submit buttons in the same form/page

How to handle Multiple submit buttons in the same form/page

Handle Multiple submit buttons in single page

Scenario :

For example, we have a login form with “sign in”,”sign up” and “cancel” button. In this scenario, “sign in” will redirect/do some action,same like sign up and cancel. Lets we discuss how to handle multiple button in same form (calling different action method).

View :

Let we create view with three submit button.

Controller

Here i am going to create three separate action method for signin,signup,cancel for capture the click event in the controller.

Custom ActionNameSelectorAttribute  :

Here we going to implement a custom ActionMethodSelectorAttribute to check which button submitted the form.This contains values posted in the form in a NameValueCollection object.

Note : While clicking the button, MultipleButtonAttribute method will execute first to know which action Mthod to call

OUTPUT :

Multiple submit buttons1

[/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]
READ  How to create simple WebGrid in MVC (Razor engine)

One Comment

  1. Mike December 30, 2015 at 9:47 am

    Hey very nice blog!

Leave A Comment