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
}
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.ActionParameterswhich 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).IdAll 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.