Icemanind Icemanind - 5 months ago 30
C# Question

Getting controller name from razor

I seem to be having a difficult getting something that should be easy. From within my view, using Razor, I'd like to get the name of the current controller. For example, if I'm here:

How can I get the controller name,
from a Razor expression:

@* Obviously this next line doesn't work

I'm new to MVC, so if this is an obvious answer, don't attack me to bad.

    var controllerName = this.ViewContext.RouteData.Values["controller"].ToString();


    var controllerName = HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString();