I have a generic action filter, and i want to get current model in the OnActionExecuting
method. My current implementation is like below:
public
In case your controller action has multiple arguments and in your filter you want to select the one that is bound via [FromBody]
, then you can use reflection to do the following:
public void OnActionExecuting(ActionExecutingContext context)
{
foreach (ControllerParameterDescriptor param in context.ActionDescriptor.Parameters) {
if (param.ParameterInfo.CustomAttributes.Any(
attr => attr.AttributeType == typeof(FromBodyAttribute))
) {
var entity = context.ActionArguments[param.Name];
// do something with your entity...