Skip to content

Instantly share code, notes, and snippets.

@mgroves
Created February 15, 2012 04:03
Show Gist options
  • Select an option

  • Save mgroves/1833093 to your computer and use it in GitHub Desktop.

Select an option

Save mgroves/1833093 to your computer and use it in GitHub Desktop.
OnActionExecuted kitchen sink
[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