Пример #1
0
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            // Only export if ModelState is not valid.
            if (context.ModelState != null && !context.ModelState.IsValid && IsRedirect(context))
            {
                var controller = context.Controller as Controller;
                if (controller != null)
                {
                    controller.TempData[Key] = ModelStateHelpers.SerializeModelState(context.ModelState);
                }
            }

            base.OnActionExecuted(context);
        }
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (!filterContext.ModelState.IsValid && filterContext.ActionDescriptor is ControllerActionDescriptor cad)
            {
                if (filterContext.Result is RedirectResult ||
                    filterContext.Result is RedirectToRouteResult ||
                    filterContext.Result is RedirectToActionResult)
                {
                    var modelState = ModelStateHelpers.SerializeModelState(filterContext.ModelState);
                    filterContext.HttpContext.Session.SetString(cad.ActionName, modelState);
                }
            }

            base.OnActionExecuted(filterContext);
        }