I was wondering how to get a URL given the area, controller and action names. So far all I have managed to come up with is:
var httpContext = new HttpContextWrapper(HttpContext.Current);
var routeData = RouteTable.Routes.GetRouteData(httpContext);
if (routeData != null) {
var virtualPath = routeData.Route.GetVirtualPath(new RequestContext(httpContext, routeData), new RouteValueDictionary(new { area = "Pages", controller = "Home", action = "Index" }));
if (virtualPath != null)
newNode.Url = "~/" + virtualPath.VirtualPath;
}
However it does not work. I was wondering if someone could help.
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…