Yair Nevet
Yair Nevet

Reputation: 13003

ActionDescriptor.ActionParameters in ActionExecutedContext

There is any thing like the ActionExecutingContext's ActionDescriptor.ActionParameters property in the ActionExecutedContext class?

I need to investigate the action's parameters at this stage(OnActionExecuted).

Upvotes: 4

Views: 8034

Answers (3)

Xin
Xin

Reputation: 79

you can get value in OnActionExecuting method:

public override void OnActionExecuting(ActionExecutingContext filterContext)
{    
  var parameters = filterContext.ActionDescriptor.GetParameters();
  if (parameters.Length >= 1)
  {
    var p = parameters[0];
    var val = filterContext.ActionParameters[p.ParameterName];
    Type type = p.ParameterType;
  }
}

Upvotes: -1

basarat
basarat

Reputation: 275997

You can get the parameters and the values like so :

// Format the parameters based on our requirements: 
StringBuilder parameters = new StringBuilder();
foreach (var p in filterContext.ActionDescriptor.GetParameters())
{
     if (filterContext.Controller.ValueProvider.GetValue(p.ParameterName) != null)
     {
           parameters.AppendFormat("\r\n\t{0}\t\t:{1}", p.ParameterName,
                       filterContext.Controller.ValueProvider.GetValue(p.ParameterName).AttemptedValue);
     }
}

Upvotes: 8

Cheng Chen
Cheng Chen

Reputation: 43523

Do you want the ActionExecutedContext.ActionDescriptor.GetParameters() method? AFAIK there is no such a ActionDescriptor.ActionParameters property. Is it because in your code there is a derived class of ActionDescriptor?

Upvotes: 0

Related Questions