0

I need to run some code after action executed using ActionFilter based on a property in the action Model, How to get a value of the property inside OnActionExecuted?

Model

public class Profile
{
        public Guid Id { get; set; }
        public string Name { get; set; }
}

Action

public BotProfileDTO Update(Profile profile)
{

}

Action Filter

public override void OnActionExecuted(ActionExecutedContext context)
{
       //How to get profile Id here
}
Fakhry
  • 49
  • 1
  • 9

1 Answers1

0

There's quite a lot inside context, so if you poke around inside it you'll find all sorts of useful things.

In your case, I think what you want lives in context.ActionParameters which is a collection of the parameters passed to the controller endpoint. If you know that your method should always receive one and only one parameter, you could access it with something like:

var myId = (context.ActionParameters.Single().Value as Profile).Id

All typical notes and caveats regarding Single() and casting apply here, so make sure you grab the parameter from the collection in the right way for your case.

trademark
  • 565
  • 4
  • 21