I’ve this action filter that executes before all the action methods executes.
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
//code omitted
UpdateModel(MyModel);
}
I want this action to update the model when actions A, B, C are supposed to execute, not D. How do I prevent this filter action from updating the model when D will execute? So is it possible to know using the ActionExecutingContent filterContext above?
Thanks
You do it by decorating actions A, B, and C with the attribute, but not D.
You have recieved an answer, but it would be really bad practice to this the way you intend. What if someone else writes an action method in another controller where this attribute should run, and then, by chance, chooses a name that you have filtered away. The attribute won’t run – a clear bug – but it will do exactly as it is told. It will be a maintainence nightmare.
No, the clean way to do this would be to move the application of the attribute from controller level to action method level for all controllers where there are action methods that shouldn’t have this attribute. That makes it easy to see, just by looking at the controller code, when the attribute will run and when not., and it will work just as expected.