开发者

Accessing ViewContext from class library

开发者 https://www.devze.com 2023-02-02 07:23 出处:网络
Is it开发者_JAVA百科 possible to access ViewContext from class library? I am in need of getting names of current View and Controller\'s action. I added both System.Web.dll and System.Web.Mvc in my cla

Is it开发者_JAVA百科 possible to access ViewContext from class library? I am in need of getting names of current View and Controller's action. I added both System.Web.dll and System.Web.Mvc in my class library project but still unable to find a way to get what I require. Although I can access current context using System.Web.HttpContext.Current.


You can access current route information like this:

var httpContext = new HttpContextWrapper(HttpContext.Current);
var routeData = System.Web.Routing.RouteTable.Routes.GetRouteData(httpContext);

var controllerName = routeData.Values["controller"].ToString();
var actionName = routeData.Values["action"].ToString();
0

精彩评论

暂无评论...
验证码 换一张
取 消