I'm working on an MVC.NET 2.0 project where I'm trying to put in some special error handling logic in the OnException method of the controller. Basically I want to be able to determine the result type of the controller method in which the unhandled exception was raised, so that I can return error data in a certain format dependent upon the type (json for JsonResult and html for ActionResult). Can anyone point me to a way to determine that type? I would greatly appreciate any help.
Thanks in advance
Assuming you didn´t change the default routing:
protected override void OnException(ExceptionContext filterContext)
{
var action = filterContext.RouteData.Values["action"].ToString();
var type = filterContext.Controller.GetType();
var method = type.GetMethod(action);
var returnType = method.ReturnType;
//...do whatever here...
}
Good luck!