In MVC3, how to get the current action name?

后端 未结 2 1725
天命终不由人
天命终不由人 2021-01-13 01:30

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 = Http         


        
2条回答
  •  说谎
    说谎 (楼主)
    2021-01-13 02:20

    var routeValues = HttpContext.Current.Request.RequestContext.RouteData.Values;
    if (routeValues != null) 
    {
        if (routeValues.ContainsKey("action"))
        {
            var actionName = routeValues["action"].ToString();
        }
    }
    

提交回复
热议问题