Which action is executing during an HtmlHelper extension method
I'm working on a menu-generating HtmlHelper extension method. This method will need to know which Action is being executed. So if Home/Index is executing, the extension method would show all links to other actions that're "coordinated." In a sense, all I need to know during the execution of the Home controller's Index action is the name of the Controller and the name of the Action that are being executed so that other logic can be executed. Is this possible?
var action = HtmlHelper.ViewContext.RouteData.Values["action"]; var controller = HtmlHelper.ViewContext.RouteData.Values["controller"];
I do something similar with a filter attribute. You can get the action name like this:
I use this to disable the menu item that represents the current context.
I need something like this, but not quite. I would love to be able to get some strongly typed way of knowing which action is executing.
So clarify in doing AOP where i only allow access to a given action if the user has rights for that action.
The problem with using a string for determining which rule to check for, is that if some developer renames an action, I wont get a compile error telling me that my rule is broken.