0

In my MVC application I have several submit buttons insde one form tag. How can I indicate what exactly button hes been pressed in my controller with [AcceptVerbs(HttpVerbs.Post)]?

Thanks!

Kirk Woll
  • 76,112
  • 22
  • 180
  • 195
ihorko
  • 6,855
  • 25
  • 77
  • 116
  • possible duplicate of [MVC Razor Buttons](http://stackoverflow.com/questions/6353511/mvc-razor-buttons) – Kirk Woll Sep 14 '11 at 15:24

3 Answers3

3

I think this will give you what you're looking for: Multiple buttons

You basically wrap each input in its own BeginForm/EndForm and assign it to seperate action methods.

Community
  • 1
  • 1
Jack Marchetti
  • 15,536
  • 14
  • 81
  • 117
1

Why do you not get them to POST to different controller methods?

If they do different things that would seemt o seperate concern better

Pharabus
  • 6,081
  • 1
  • 26
  • 39
0

You can do a simple test for the button name since only one submit button will get posted at a time.

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult MyForm (FormCollection form)
{
  bool isButton1 = form.AllKeys.Contains ("Button1");
  bool isbutton2 = form.AllKeys.Contains ("Button2");

  ...
}
Todd Smith
  • 17,084
  • 11
  • 59
  • 78