I\'m trying to fetch the current page from my shared layout in .net mvc app so that I can load a different favicon icon for the 2 different pages.
I\'ve tried something
You can get your current controller name & action method name from your RouteData dictionary.
@{
var controllerName = string.Empty;
object controllerObj;
var actionName = string.Empty;
object actionObj;
if (ViewContext.RouteData.Values.TryGetValue("controller", out controllerObj))
{
controllerName = controllerObj.ToString();
}
if (ViewContext.RouteData.Values.TryGetValue("action", out actionObj))
{
actionName = actionObj.ToString();
}
}