Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vgaltes/89ba835dc74336d68808 to your computer and use it in GitHub Desktop.
Save vgaltes/89ba835dc74336d68808 to your computer and use it in GitHub Desktop.
MultipleFormActionsButtonWithParameterAttribute
[AttributeUsage(AttributeTargets.Method)]
public class MultipleFormActionsButtonWithParameterAttribute : ActionNameSelectorAttribute
{
public string SubmitButtonActionName { get; set; }
public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
{
var value = controllerContext.Controller.ValueProvider.GetValue(SubmitButtonActionName);
string realActionName;
var isValid = false;
if (value == null)
{
realActionName = actionName.Split('-').First();
isValid = methodInfo.Name.Equals(realActionName, StringComparison.InvariantCultureIgnoreCase);
}
else
{
realActionName = value.AttemptedValue.Split('-').First();
isValid = realActionName == methodInfo.Name;
}
return isValid;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment