There is no model in the OnActionExecuting
event OnActionExecuting
. The model is returned by the action of the controller. So you have a model inside the OnActionExecuted
event. This is where you can change the values. For example, if we assume that your controller action returned a ViewResult and passed it some model here, how could you get this model and change some property:
public class MyActionFilterAttribute : ActionFilterAttribute { public override void OnActionExecuted(ActionExecutedContext filterContext) { var result = filterContext.Result as ViewResultBase; if (result == null) {
If you want to change the value of some property of the view model that is passed as an action argument, I would recommend doing this in a custom mediator. But this is also possible to achieve in the OnActionExecuting
event:
public class MyActionFilterAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { var model = filterContext.ActionParameters["model"] as MyViewModel; if (model == null) {
source share