public class SomeController { public ActionResult TheAction(string whichButton, UserData userData) { if(whichButton == "Back") { // do the back action } else if(whichButton == "Next") { // do the next action } else if(whichButton == "Save") { // do the save action } throw Exception(""); } }
Encontrei este artigo de Mark Needham, que utiliza um Dictionary e uso de Generics:
public class SomeController { private Dictionary<string, Func<UserData,ActionResult>> handleAction = new Dictionary<string, Func<UserData,ActionResult>>
{ { "Back", SaveAction }, { "Next", NextAction }, { "Save", SaveAction } }; public ActionResult TheAction(string whichButton, UserData userData) { if(handleAction.ContainsKey(whichButton)) { return handleAction[whichButton](userData); } throw Exception(""); } private ActionResult NextAction(UserData userData) { // do cool stuff } }
Nenhum comentário:
Postar um comentário