vatsal vatsal - 1 year ago 141
C# Question

Get Action Method original name if its decorate with ActionName MVC attribute

I am using action filter in my MVC code i have attached action filter with below mentioned action, but this action is decorate with MVC action name attribute.

But i want action method original name(ex. ChangeOrder) but i got in action filter name as a edit. I don't want to remove ActionName attribute.

[HttpPost, ActionName("Edit")]
public ActionResult ChangeOrder(int id)
return View();

Should i get Actionmethod original name without removing ActionName attribute.
please provide me way how to get original name not decorated name in mvc.

Answer Source

You can get the action method details corresponding to the ActionName after casting filterContext.ActionDescriptor to the ReflectedActionDescriptor. This object has MethodInfo property which gives you all details of the method.

string actionMethodName = (filterContext.ActionDescriptor as ReflectedActionDescriptor)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download