I need to be able to get a controller name in my custom helper class.
I have the following:
- Layout view which calls a controller: "HelperController", action: "Menu" like so:
@Html.Action("Menu", "Helper")
This calls ActionResult and generages an html:
@model List<MvcMenuItem> @{ Layout = null; } @{ @Html.Menu(this.ViewContext).ClientId("navMain").AddRange(Model).Render() }
This calls "
public static class MvcMenuExtensions
" and in there (in myRender()
method) I need to be able to get the controller name I'm currently in, NOT the controller name that is callingMvcMenuExtensions
I've tried this:
string controller = this.ViewContext.RouteData.Values["controller"].ToString();
but this results in controller being "Helper
" controller and not the current controller I'm in. Since this "ActionResult
" is being called from anywhere on the page (it's in the layout).
Thanks