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
You should not call a controller from the view. Add a property to your view model, set it in the controller, and use it in the view.
3 Answers. Show activity on this post. You can decorate each method that needs logging with [Logger] or do it at the controller level to log every single call that happens inside that controller. Lastly, you can make your action filter global so that it will run everytime any action is called inside your project.
I know It's late but maybe someone can benefit from it
ControllerName: ControllerContext.ActionDescriptor.ControllerName
ActionName: ControllerContext.ActionDescriptor.ActionName
You have access to controller name in the
ControllerContext.ActionDescriptor.ControllerName
property, given that the action descriptor is of ControllerActionDescriptor
type
Reference ControllerActionDescriptor.ControllerName
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