I realise this question is ancient but just ran into it so thought I'd answer!
This is what we use:
/// <summary>
/// Attribute for Controller methods to decide whether a particular button
/// was clicked and hence whether the method can handle the action.
/// </summary>
public class IfButtonClickedAttribute : ActionMethodSelectorAttribute
{
private readonly IEnumerable<string> _buttonNames;
public IfButtonClickedAttribute(params string[] buttonNames)
{
_buttonNames = buttonNames;
}
public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
{
if (controllerContext.HttpContext.Request.HttpMethod != "POST")
return false;
foreach (string buttonName in _buttonNames)
{
//this first test is for buttons or inputs that have the actual name specified
if (controllerContext.HttpContext.Request.Form[buttonName] != null)
return true;
}
return false;
}
}
Then on your Actions you go:
[ActionName("SaveItem"), IfButtonClicked("SaveAsDraft")]
public ActionResult SaveAsDraft(){ ... }
[ActionName("SaveItem"), IfButtonClicked("SaveAsPublished")]
public ActionResult SaveAsPublished(){ ... }
ID's don't matter, theNameis what matters. Is that a different value? It sounds like there might be a simplier approach to what you're looking for. Providing some more detail might help.