/// <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")); } }
/// <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() { ITreeNode FoundNode = _exampleService.GetCurrentNode(); if (FoundNode != null) { ExampleMVCWebPartsViewModel Model = new ExampleMVCWebPartsViewModel(); // Get subnav items from the ExampleService Model.SubNavigation = _exampleService.GetSubNavFromNode(FoundNode); return(View(Model)); } else { return(HttpNotFound("Could not find page by that Url")); } }