I have a global ActionFilter executing on each ActionResult. Is it possible to detect the ActionResult type (such as a JsonResult vs. an ActionResult) inside the ActionFilter?
For instance, I want the ActionFilter to immediately exit here:
public JsonResult someAjaxAction()
{
}
But I'd like it to do it's magic here:
public ActionResult PageView()
{
}
Yes, I know I could just use an ActionFilter attribute and decorate the actions I'd like to execute this on, but I'd like to keep it as a global ActionFilter and detect inside the action whether I need to perform the desired work.
public class MyActionFilterAttribute : ActionFilterAttribute
{
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
if (filterContext.Result is ViewResult)
{
...
}
else if (filterContext.Result is JsonResult)
{
...
}
...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With