/// <summary> /// Called before the action executes, after model binding is complete /// </summary> /// <param name="context">A context for action filters</param> public void OnActionExecuting(ActionExecutingContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } //check whether this filter has been overridden for the Action var actionFilter = context.ActionDescriptor.FilterDescriptors .Where(filterDescriptor => filterDescriptor.Scope == FilterScope.Action) .Select(filterDescriptor => filterDescriptor.Filter).OfType <PublishModelEventsAttribute>().FirstOrDefault(); //whether to ignore this filter if (actionFilter?.IgnoreFilter ?? _ignoreFilter) { return; } if (context.HttpContext.Request == null) { return; } //only in POST requests if (!context.HttpContext.Request.Method.Equals(WebRequestMethods.Http.Post, StringComparison.InvariantCultureIgnoreCase)) { return; } //model received event foreach (var model in context.ActionArguments.Values.OfType <BaseNopModel>()) { //we publish the ModelReceived event for all models as the BaseNopModel, //so you need to implement IConsumer<ModelReceived<BaseNopModel>> interface to handle this event _eventPublisher.ModelReceived(model, context.ModelState); } }