public override void OnActionExecuted(ActionExecutedContext context) { if (!context.ModelState.IsValid) { if (context.Result is RedirectResult || context.Result is RedirectToRouteResult || context.Result is RedirectToActionResult) { if (context.Controller is Controller controller && context.ModelState != null) { var modelState = ModelStateHelper.SerializeModelState(context.ModelState); controller.TempData[Key] = modelState; } } } base.OnActionExecuted(context); }