1. Back To Blog

How can you handle multiple submit buttons? (ASP.NET MVC Interview Questions)

Let us try to understand what the interviewer is asking.

If you have two submit buttons as shown in the below code and you want that when end user click first submit button, "X" action should fire and in the other submit button click "Y" action should fire. What is the best way to achieve the same?.

The first way is by creating two form tags and every submit button goes in to those individual form tags as shown in the below code. So if you click on submit button "sub1" it will post to "Action1" and if the end user clicks on "sub2" it will post to "Action2".

In case the interviewer complains that the above approach is not AJAX. Then you can give the below Javascript and JQUERY approach. So in every submit button click we are invoking their respective functions and in their respective functions we are invoking JQUERY POST's.

Do not forget to download our 100 ASP.NET MVC Interview question ebook

If you are completely new to ASP.NET MVC you can start with below free youtube video which teaches MVC 5 from scratch.

Shiv Prasad Koirala

Visit us @ www.questpond.com or call us at 022-66752917... read more

We are on Social