How can I do button post in MVC4 with more than 1 button [Resolved]

Posted by Trjineesh under ASP.NET MVC on 12/1/2014 | Points: 10 | Views : 672 | Status : [Member] | Replies : 1
Hi,

I am new to MVC4 and to ASP too. I have a form with two buttons. While I press any of the button, control goes to the same Post method. Is there any way to differenciate the buttons in the controller.

Thanks & Regards
Jineesh TR




Responses

Posted by: kgovindarao523-21772 on: 12/2/2014 [Member] [MVP] Bronze | Points: 50

Up
0
Down

Resolved
Hi,

Yes, We can differentiate which button you have clicked by using button name.
Ex:
<input type="submit" name="action" value="SUBMIT"/>
<input type="submit" name="action" value="RESET"/>


Now, In your MVC POST method.
[HttpPost]
public ActionResult Index(string action)
{

}
Now, if you click on SUBMIT button, the string "action" value is SUBMIT,
and if you click on RESET button, the string "action" value is RESET.
you can differentiate like this.

Please mark as answer if this answer helps you.


Thank you,
Govind

Trjineesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response