Exemplo n.º 1
0
        public static string RenderSitecorePlaceHolder(string key)
        {
            var sublayoutId = GetSublayoutIdFromPlaceHolder(Sitecore.Context.Item[Sitecore.FieldIDs.LayoutField], key);
            if (!string.IsNullOrEmpty(sublayoutId))
            {
                var layoutItem = Sitecore.Context.Database.GetItem(ID.Parse(sublayoutId));
                var controllerName = layoutItem.Fields["Controller"].Value;
                var actionName = layoutItem.Fields["Action"].Value;

                HttpContext.Current.RewritePath(string.Concat("/", controllerName, "/", actionName));

                RouteData routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current));
                if (routeData != null)
                {
                    var factory = new ControllerFactory();
                    var httpContextBase = new HttpContextWrapper(HttpContext.Current);
                    var context = new RequestContext(httpContextBase, routeData);
                    Type type = factory.GetController(context, controllerName);

                    if (type != null)
                    {
                        var controller = (Controller)factory.GetController(context, type);

                        var controllerContext = new ControllerContext(httpContextBase, routeData, controller);
                        var viewContext = new ViewContext(controllerContext, new FakeView(), controller.ViewData, controller.TempData, TextWriter.Null);

                        var helper = new HtmlHelper(viewContext, new ViewPage());

                        return helper.Action(actionName, controllerName).ToHtmlString();
                    }
                }
                HttpContext.Current.RewritePath("default.aspx");
            }
            return "";
        }
Exemplo n.º 2
0
        protected override void DoRender(HtmlTextWriter writer)
        {
            HttpContext.Current.RewritePath(HttpContext.Current.Request.RawUrl);
            RouteData routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current));
            if (routeData == null) return;
            object controllerName = "";
            object actionName = "";
            routeData.Values.TryGetValue("action", out actionName);
            routeData.Values.TryGetValue("controller", out controllerName);

            if (Sitecore.Context.Item.Fields["ControllerName"] != null)
            {
                controllerName = GetControllerName(routeData);
                actionName = GetActionName(routeData);
            }

            var factory = new ControllerFactory();
            var httpContextBase = new HttpContextWrapper(HttpContext.Current);
            var context = new RequestContext(httpContextBase, routeData);
            Type type = factory.GetController(context, (string)controllerName);

            if (type != null)
            {
                IController controller = factory.GetController(context, type);
                MvcPartialHelper.RenderPartial((string)actionName, null, (Controller)controller, routeData);
            }
        }
Exemplo n.º 3
0
        protected override void DoRender(HtmlTextWriter writer)
        {
            HttpContext.Current.RewritePath(string.Concat("/", Controller, "/", Action));
            RouteData routeData = RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current));
            if (routeData != null)
            {
                var factory = new ControllerFactory();
                var httpContextBase = new HttpContextWrapper(HttpContext.Current);
                var context = new RequestContext(httpContextBase, routeData);
                Type type = factory.GetController(context, Controller);

                if (type != null)
                {
                    IController controller = factory.GetController(context, type);
                    MvcPartialHelper.RenderPartial(Action, null, (Controller)controller, routeData);
                }
            }
            HttpContext.Current.RewritePath("default.aspx");
        }