/// <summary> /// This Repeater "Web Part" is given the ViewBag (since it's normally not available on child actions) and configures itself from this. /// This allows for easy calling and adjustment to this "Web Parts" Logic without really needing adjustments on the calling Views, but /// is very much tied into the source (ex: Kentico). It would be hard to flip this with Kentico Cloud if you wished to use that. /// </summary> /// <param name="ViewBag">The ViewBag which will have the Document, Culture, and Site Context</param> /// <returns></returns> public ActionResult NavigationByContext(dynamic ViewBag) { // Build the actual Partial View's model from the data provided by the parent View ExampleMVCWebPartsSubNavs Model = new ExampleMVCWebPartsSubNavs(); var subNavs = new List <SubNav>(); // Get the Sub Nav Items foreach (ITreeNode Node in DocumentQueryHelper.RepeaterQuery( Path: ViewBag.CurrentDocument.NodeAliasPath + "/%", CultureCode: ((CultureInfo)ViewBag.CurrentCulture).CultureCode, SiteName: ((ISiteInfo)ViewBag.CurrentSite).SiteName, ClassNames: "CMS.MenuItem", OrderBy: "NodeLevel, NodeOrder", Columns: "MenuItemName,NodeAliasPath" )) { subNavs.Add(new SubNav() { LinkText = Node.GetValue("MenuItemName").ToString(), // You have to decide what your URL will be, for us our URLs = NodeAliasPath LinkUrl = Node.NodeAliasPath }); } Model.SubNavigation = subNavs; return(View("Navigation", Model)); }
/// <summary> /// This Repeater "Webpart" Relies on just a path that would be provided through the View's context. Does not rely on passing /// the ViewBag like the NavigationByContext, but does then require the calling View to provide the properties, and if ever more /// properties are needed, would need to adjust both Controller and View alike. /// </summary> /// <returns></returns> public ActionResult NavigationByPath(string Path, string Culture, string SiteName) { // Build the actual Partial View's model from the data provided by the parent View ExampleMVCWebPartsSubNavs Model = new ExampleMVCWebPartsSubNavs(); List <SubNav> SubNavs = new List <SubNav>(); // Get the Sub Nav Items foreach (TreeNode Node in DocumentQueryHelper.RepeaterQuery( Path: Path + "/%", CultureCode: Culture, SiteName: SiteName, 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("Navigation", Model)); }
/// <summary> /// This Repeater "Webpart" Relies on just a path that would be provided through the View's context. Does not rely on passing /// the ViewBag like the NavigationByContext, but does then require the calling View to provide the properties, and if ever more /// properties are needed, would need to adjust both Controller and View alike. /// </summary> /// <returns></returns> public ActionResult NavigationByPath(string Path, string Culture, string SiteName) { // Build the actual Partial View's model from the data provided by the parent View ExampleMVCWebPartsSubNavs Model = new ExampleMVCWebPartsSubNavs(); // Get the Sub Nav Items from the ExampleService Model.SubNavigation = _exampleService.GetSubNavFromAliasPath(Path, CultureInfoProvider.GetCultureInfo(Culture)); return(View("Navigation", Model)); }
/// <summary> /// This Repeater "Web Part" relies completely on being passed the proper Model which is platform agnostic, so you could /// provide a List of SubNavs generated from Kentico, Kentico Cloud, or some other source. /// </summary> /// <param name="SubNavs">The Sub Nav List (Passed from the View's Model)</param> /// <returns></returns> public ActionResult NavigationByModel(IEnumerable <SubNav> SubNavs) { // Build the actual Partial View's model from the data provided by the parent View ExampleMVCWebPartsSubNavs Model = new ExampleMVCWebPartsSubNavs() { SubNavigation = SubNavs }; return(View("Navigation", Model)); }