Ejemplo n.º 1
0
        /// <summary>
        /// Renders the current (Include) Page as a Region.
        /// </summary>
        /// <param name="htmlHelper">The HtmlHelper instance on which the extension method operates.</param>
        /// <returns>The rendered HTML.</returns>
        public static MvcHtmlString DxaRegion(this HtmlHelper htmlHelper)
        {
            using (new Tracer(htmlHelper))
            {
                PageModel pageModel = (PageModel)htmlHelper.ViewData.Model;

                // Create a new Region Model which reflects the Page Model
                string  regionName = pageModel.Title;
                MvcData mvcData    = new MvcData
                {
                    ViewName           = regionName,
                    AreaName           = SiteConfiguration.GetDefaultModuleName(),
                    ControllerName     = SiteConfiguration.GetRegionController(),
                    ControllerAreaName = SiteConfiguration.GetDefaultModuleName(),
                    ActionName         = SiteConfiguration.GetRegionAction()
                };

                RegionModel regionModel = new RegionModel(regionName)
                {
                    MvcData = mvcData
                };
                regionModel.Regions.UnionWith(pageModel.Regions);

                return(htmlHelper.DxaRegion(regionModel));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Renders a given Region Model
        /// </summary>
        /// <param name="htmlHelper">The HtmlHelper instance on which the extension method operates.</param>
        /// <param name="region">The Region Model to render. This object determines the View that will be used.</param>
        /// <param name="containerSize">The size (in grid column units) of the containing element.</param>
        /// <returns>The rendered HTML or an empty string if <paramref name="region"/> is <c>null</c>.</returns>
        public static MvcHtmlString DxaRegion(this HtmlHelper htmlHelper, RegionModel region, int containerSize = 0)
        {
            if (region == null)
            {
                return(MvcHtmlString.Empty);
            }

            if (containerSize == 0)
            {
                containerSize = SiteConfiguration.MediaHelper.GridSize;
            }

            using (new Tracer(htmlHelper, region, containerSize))
            {
                MvcData mvcData            = region.MvcData;
                string  actionName         = mvcData.ActionName ?? SiteConfiguration.GetRegionAction();
                string  controllerName     = mvcData.ControllerName ?? SiteConfiguration.GetRegionController();
                string  controllerAreaName = mvcData.ControllerAreaName ?? SiteConfiguration.GetDefaultModuleName();

                MvcHtmlString result = htmlHelper.Action(actionName, controllerName, new { Region = region, containerSize = containerSize, area = controllerAreaName });

                if (WebRequestContext.IsPreview)
                {
                    result = new MvcHtmlString(Markup.TransformXpmMarkupAttributes(result.ToString()));
                }
                return(Markup.DecorateMarkup(result, region));
            }
        }