コード例 #1
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            // If the ModelState is valid then probably we won't be using the PRG method, so don't store the state
            // unless the user really wants to
            if (!_alwaysPreserve && filterContext.ModelState.IsValid)
            {
                return;
            }

            //Export if we are redirecting
            if (!(filterContext.Result is RedirectResult) &&
                !(filterContext.Result is RedirectToRouteResult) &&
                !(filterContext.Result is RedirectToActionResult))
            {
                return;
            }

            if (!(filterContext.Controller is Controller controller) || filterContext.ModelState == null)
            {
                return;
            }

            string modelState = ModelStateHelpers.SerialiseModelState(filterContext.ModelState);

            controller.TempData[_key] = modelState;
            base.OnActionExecuted(filterContext);
        }
コード例 #2
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);

            Controller controller = filterContext.Controller as Controller;

            if (!(controller?.TempData[_key] is string serialisedModelState))
            {
                return;
            }

            //Only Import if we are viewing
            if (!(filterContext.Result is ViewResult))
            {
                return;
            }

            ModelStateDictionary modelState = ModelStateHelpers.DeserialiseModelState(serialisedModelState);

            filterContext.ModelState.Merge(modelState);
        }