ASP.NET MVC – Multiple Buttons on a Form
this is what I am trying to do too, except the first answer doesn’t satisfy my requirements and the second one uses formcollection. I am not passing formcollection. I am passing values to the ActionResult method, because in my scenario, it doesn’t make much sense to use formcollection, because user is hardly filling out any data.
I really prefer using SubmitImage at the moment, so I would prefer if your solution doesn’t involve me switching to css or input type etc.
EDIT: I’m using Ajax.BeginForm and that seems to be the problem rather than Html.SubmitImage
The only way to determine which button was pressed (without using Javascript), is to examine the data that the browser sends when you submit the form. This doesn’t have anything to do with whether the user fills out a form or not, it only has to do with how you do the request to the server.
If you use the POST method in the form, you get the name of the button in the form collection, otherwise you get it in the querystring collection.
Of the buttons, only the one that is used to post the form is included in the data, so you just check which one exists: