Skip to content

Instantly share code, notes, and snippets.

@davybrion
Created May 18, 2012 14:16
Show Gist options
  • Save davybrion/2725488 to your computer and use it in GitHub Desktop.
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?
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