I'm trying to create custom html helper that will retrieve some text from XML file and render it on the view. XML is organized in hierarchy where top nodes represent controller names, following the action names and then individual keys.
Goal is to accomplish syntax such as:
@Html.Show("Title")
Where helper would infer controller name and action name from the view where it was called.
Is there a way to get that information in the html helper extension method?
ControllerContext(HttpContextBase, RouteData, ControllerBase) Initializes a new instance of the ControllerContext class by using the specified HTTP context, URL route data, and controller.
Even simpler:
htmlHelper.ViewContext.RouteData.Values["controller"]
and
htmlHelper.ViewContext.RouteData.Values["action"]
gives you the controller and action name, respectively.
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