Reputation: 1970
I know that in asp.net-core 2.2, I can get the action name as follows:
ControllerContext.ActionDescriptor.ActionName
but I am looking for a way to get the controller name of the current request/page in asp.net-core 2.2
I will appreciate any guide.
Thank you
Upvotes: 12
Views: 21772
Reputation: 799
There are situations where your ControllerContext will be null and you end up with nothing. I recommend using reflection.
this.GetType().Name
Upvotes: 0
Reputation: 189
I know It's late but maybe someone can benefit from it
ControllerName: ControllerContext.ActionDescriptor.ControllerName
ActionName: ControllerContext.ActionDescriptor.ActionName
Upvotes: 9
Reputation: 247591
You have access to controller name in the
ControllerContext.ActionDescriptor.ControllerName
property, given that the action descriptor is of ControllerActionDescriptor
type
Reference ControllerActionDescriptor.ControllerName
Upvotes: 21