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
  • 73,473
  • 21
  • 178
  • 189
ihorko
  • 6,509
  • 25
  • 75
  • 112
  • 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,254
  • 13
  • 78
  • 116
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,031
  • 1
  • 25
  • 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
  • 16,644
  • 11
  • 56
  • 77