Click here to Skip to main content
15,916,042 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am handling error using HandleError attribute and want to know where exception occurs i am doing that in OnException method bur getting above error beacuse i have two methods with same name one is [HttpGet] and other is [HttpPost] eg Create..but that i cant change...so how to fetch action name and controller name ??plz help..

//code

protected override void OnException(ExceptionContext filterContext)
{
C#
string actionName = filterContext.RouteData.Values["action"].ToString();
                Type controller = filterContext.Controller.GetType();
                var method = controller.GetMethod(actionName); //error 'ambigous match found'
                var returnType = method.ReturnType;


}
Posted

You could change your code and use GetMethods() instead of GetMethod, filter the results by your actionName, and then manage both cases (for both attributes: HttpGet and HttpPost).
 
Share this answer
 
Comments
Member 9579525 12-Mar-14 1:16am    
i want retutn type of method whether it is ActionResult or JsonResult..i have tried
var method = controller.GetMethods();
var returnType = method.GetType();
but its not working..
Raul Iloc 12-Mar-14 14:27pm    
GetMethods() returns an array of type MethodInfo, so you have to filter the items from this array then to use the property of them (like item.ReturnType).
GetMethods() returns an array of type MethodInfo, so you have to filter the items from this array then to use the property of them (like item.ReturnType).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900