Skip to content

Instantly share code, notes, and snippets.

@vgaltes
Created December 6, 2015 22:01
Show Gist options
  • Save vgaltes/514271a33f33daa51cbb to your computer and use it in GitHub Desktop.
Save vgaltes/514271a33f33daa51cbb to your computer and use it in GitHub Desktop.
FillParameterFromActionName
public class FillParameterFromActionName : ActionFilterAttribute
{
public string ParameterName { get; set; }
public string SubmitButtonActionName { get; set; }
public TypeCode ParameterType { get; set; }
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var value = filterContext.HttpContext.Request.Params[SubmitButtonActionName];
var parameterValue = value.Split('-').Last();
var realParameterValue = Convert.ChangeType(parameterValue, ParameterType);
filterContext.ActionParameters[ParameterName] = realParameterValue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment