Current action from controller code .NET

Published on Tuesday, September 8, 2015

Knowing the current action and controller that are being used can be handy when working with menus. Below is one way of retrieving this in the current controller context.

var currentAction = ControllerContext.ParentActionViewContext.RouteData.Values["action"].ToString();
var currentController = ControllerContext.ParentActionViewContext.RouteData.Values["controller"].ToString();
comments powered by Disqus