In MVC3, how to get the current action name?
13,300
var routeValues = HttpContext.Current.Request.RequestContext.RouteData.Values;
if (routeValues != null)
{
if (routeValues.ContainsKey("action"))
{
var actionName = routeValues["action"].ToString();
}
}
Author by
Chris Ballance
Senior Engineering manager at Mark43 Señor Software Developer at Diligent Microsoft Alumni Code to Share Photographer BSC, MCP, CSM@ballancefacebookstudent
Updated on June 04, 2022Comments
-
Chris Ballance almost 2 years
Is there a way to use HttpContext or the View context to get the current action name?
I can get the controller name using
var routeValues = HttpContext.Current.Request.RequestContext.RouteData.Values; if (routeValues != null) { if (routeValues.ContainsKey("controller")) { controllerName = HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString(); } } }
-
Chris Ballance over 5 yearsThanks for the simplification, @PeterB!