/// <summary>
        /// Simply gets the current node using the absolute path of the HttpContext.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public ITreeNode GetCurrentNode()
        {
            var       absolutePath = _httpContextAccessor.HttpContext.Request.Url.AbsolutePath;
            ITreeNode FoundNode    = DocumentQueryHelper.GetNodeByAliasPath(absolutePath);

            return(FoundNode);
        }
        /// <summary>
        /// Example of how to do Web Parts in MVC Using RenderAction, and in this case the parent Controller is filling a model
        /// that will be passed to the "Web Part" (Action) in order to render.  More leg work but also source-agnostic. (Model-View-ViewModel MVVM)
        /// </summary>
        /// <returns></returns>
        public ActionResult MVCWebPartsViewModel()
        {
            TreeNode FoundNode = DocumentQueryHelper.GetNodeByAliasPath(HttpContext.Request.Url.AbsolutePath);

            if (FoundNode != null)
            {
                ExampleMVCWebPartsViewModel Model = new ExampleMVCWebPartsViewModel();
                // Get the Sub Nav Items
                foreach (TreeNode Node in DocumentQueryHelper.RepeaterQuery(
                             Path: FoundNode.NodeAliasPath + "/%",
                             ClassNames: "CMS.MenuItem",
                             OrderBy: "NodeLevel, NodeOrder",
                             Columns: "MenuItemName,NodeAliasPath"
                             ))
                {
                    Model.SubNavigation.Add(new SubNav()
                    {
                        LinkText = Node.GetValue("MenuItemName", ""),
                        // You have to decide what your URL will be, for us our URLs = NodeAliasPath
                        LinkUrl = Node.NodeAliasPath
                    });
                }
                return(View(Model));
            }
            else
            {
                return(HttpNotFound("Could not find page by that Url"));
            }
        }
        public ActionResult Banners()
        {
            TreeNode FoundNode = DocumentQueryHelper.GetNodeByAliasPath(HttpContext.Request.Url.AbsolutePath);

            if (FoundNode != null)
            {
                SetContext(FoundNode.DocumentID);
                // Get Banners
                ExampleBannersViewModel Model = new ExampleBannersViewModel();
                Model.BannerNameUrlsList = new List <ExampleBannersBanner>();
                foreach (TreeNode Banner in DocumentQueryHelper.RepeaterQuery(ClassNames: "Demo.Banner", RelationshipName: "Banners", RelationshipWithNodeGuid: FoundNode.NodeGUID))
                {
                    Model.BannerNameUrlsList.Add(new ExampleBannersBanner()
                    {
                        BannerName = Banner.GetValue <string>("BannerName", ""),
                        BannerUrl  = Banner.GetValue <string>("BannerImage", "")
                    });
                }
                return(View(Model));
            }
            else
            {
                return(HttpNotFound("Could not find page by that Url"));
            }
        }
        // GET: GenericWidgetPage
        public ActionResult Index()
        {
            GenericWidgetPage FoundNode = (GenericWidgetPage)DocumentQueryHelper.GetNodeByAliasPath(EnvironmentHelper.GetUrl(HttpContext.Request), GenericWidgetPage.OBJECT_TYPE);

            if (FoundNode != null)
            {
                SetContext(FoundNode.DocumentID);
                return(View(FoundNode.Layout));
            }
            else
            {
                return(HttpNotFound("Could not find page by that Url"));
            }
        }
Exemple #5
0
        public ActionResult UnregisteredTemplate()
        {
            TreeNode FoundNode = DocumentQueryHelper.GetNodeByAliasPath(EnvironmentHelper.GetUrl(HttpContext.Request));

            if (FoundNode != null)
            {
                HttpContext.Kentico().PageBuilder().Initialize(FoundNode.DocumentID);
                return(View());
            }
            else
            {
                return(new HttpNotFoundResult());
            }
        }
        /// <summary>
        /// Example of how to do Web Parts in MVC using RenderAction, and in this case no model is provided for the webpart, just using
        /// the ViewBag Context set by SetContext, similar to in Portal Method how you would use Macros.
        /// </summary>
        /// <returns></returns>
        public ActionResult MVCWebPartsNoModel()
        {
            TreeNode FoundNode = DocumentQueryHelper.GetNodeByAliasPath(HttpContext.Request.Url.AbsolutePath);

            if (FoundNode != null)
            {
                // This will give us the Node Alias Path context
                SetContext(FoundNode.DocumentID);
                return(View());
            }
            else
            {
                return(HttpNotFound("Could not find page by that Url"));
            }
        }
        // GET: HomePageTemplates
        public ActionResult Index()
        {
            // Retrieves the page from the Kentico database
            TreeNode page = DocumentQueryHelper.GetNodeByAliasPath(EnvironmentHelper.GetUrl(HttpContext.Request));

            // Returns a 404 error when the retrieving is unsuccessful
            if (page == null)
            {
                return(HttpNotFound());
            }

            // Generate your own view model.
            TemplatedPageCustomControllerViewModel Model = new TemplatedPageCustomControllerViewModel()
            {
                Message = "Hello World! Custom Message"
            };

            // Have to hard code as the normal Return View() still has routing context of Home page controller
            return(View("PageTemplates/_TemplatedPageCustomController", Model));
        }