Created
May 18, 2012 14:16
-
-
Save davybrion/2725488 to your computer and use it in GitHub Desktop.
is it alright to use this in a PRG scenario in asp.net mvc? or totally not done?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SetTempDataWhenModelStateInvalidAttribute : ActionFilterAttribute | |
{ | |
public override void OnActionExecuted(ActionExecutedContext filterContext) | |
{ | |
base.OnActionExecuted(filterContext); | |
if (!filterContext.Controller.ViewData.ModelState.IsValid) | |
{ | |
filterContext.Controller.TempData["ModelState"] = filterContext.Controller.ViewData.ModelState; | |
} | |
} | |
} | |
public class RestoreModelStateFromTempDataAttribute : ActionFilterAttribute | |
{ | |
public override void OnActionExecuting(ActionExecutingContext filterContext) | |
{ | |
base.OnActionExecuting(filterContext); | |
if (filterContext.Controller.TempData.ContainsKey("ModelState")) | |
{ | |
filterContext.Controller.ViewData.ModelState.Merge((ModelStateDictionary)filterContext.Controller.TempData["ModelState"]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment