Created
February 15, 2012 04:03
-
-
Save mgroves/1833093 to your computer and use it in GitHub Desktop.
OnActionExecuted kitchen sink
This file contains hidden or 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
| [MyCustomControllerAttribute1] | |
| [MyCustomControllerAttribute2] | |
| public class HomeController : Controller | |
| { | |
| public ActionExecutedContext FilterExecutedContext; | |
| public ActionResult Index(string id, string anotherParam) | |
| { | |
| return View(); | |
| } | |
| [KitchenSinkActionExecutedFilter] | |
| [MyCustomActionAttribute1] | |
| [MyCustomActionAttribute2] | |
| public ActionResult OnActionExecutedAction(string id, string anotherParam) | |
| { | |
| if(anotherParam == "withException") | |
| throw new SyntaxErrorException("I just wanted to throw an interesting exception!"); | |
| return View(FilterExecutedContext); | |
| } | |
| } | |
| public class KitchenSinkActionExecutedFilterAttribute : ActionFilterAttribute | |
| { | |
| public override void OnActionExecuted(ActionExecutedContext filterContext) | |
| { | |
| filterContext.ExceptionHandled = true; | |
| filterContext.Result = new ViewResult(); | |
| (filterContext.Result as ViewResult).ViewData.Model = filterContext; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment