I've got a view with multiple submit buttons, and I don't know what the best way to handle this is. At the moment one of my controller actions looks like this:
[HttpPost]
public ActionResult SaveAlbum(
string saveButton,
string createButton,
string deleteButton,
string showButton,
string myHiddenValue)
{
if (!String.IsNullOrEmpty(saveButton))
{
// do stuff
}
if (!String.IsNullOrEmpty(createButton))
{
// do stuff
}
// repeat for all buttons
var viewModel = new MyViewModel(one, two, three);
return View("Index", viewModel);
}
This looks pretty terrible. I'm assuming the best way would be to have a separate form for each submit button, which posts to different actions, but as it only posts what's inside the form and I need myHiddenValue
for all of them I don't know what I should do. Should I use multiple hidden values instead? The hidden value is a comma separated list of values for all the checked checkboxes (added with jQuery).