Esempio n. 1
0
        //public static string CurrentAction(this UrlHelper urlHelper) {
        //    var routeValueDictionary = urlHelper.RequestContext.RouteData.Values;

        //    // In case using virtual dirctory
        //    var rootUrl = urlHelper.Content("~/");
        //    return string.Format("{0}{1}/{2}/", rootUrl, routeValueDictionary["controller"], routeValueDictionary["action"]);
        //}

        public static string CurrentActionPath(this ViewContext viewContext)
        {
            var rootUrl  = viewContext.RootUrl();
            var areaName = viewContext.AreaName();

            if (!String.IsNullOrEmpty(areaName))
            {
                areaName += "/";
            }

            var controllerName = viewContext.ControllerName();
            var actionName     = viewContext.ActionName();

            return(string.Format("{0}{1}{2}/{3}/",
                                 rootUrl,
                                 areaName,
                                 controllerName,
                                 actionName));
        }