[英]Why does my root Umbraco page have no Children only when it is the currently active page?
I have the following page structure in Umbraco: 我在Umbraco中具有以下页面结构:
- Home 家
- Device Management 设备管理
- Resources 资源
- Manuals 手册
- Downloads 下载
- Terms & Conditions 条款及细则
I have a navigation menu as a partial in my Master.cshtml template which is the base template of all of these pages. 我的Master.cshtml模板中有一个导航菜单,该菜单是所有这些页面的基本模板。 In this partial I call
Model.Content.Site().Children
to get all the "Device Management" and "Resources" nodes then recurse to get any descendant nodes of these. 在这部分内容中,我调用Model.Content.Site().Children
来获取所有的“设备管理”和“资源”节点,然后递归以获取这些节点的任何后代节点。This all worked fine when all of the pages used the same Document Type (
ChildNodeSelectionPage
) but now I've changed the Home page to use a derived form of this document type (CustomChildNodeSelectionPage
) for an additional property and had to create a dummy controller (CustomChildNodeSelectionPageController
) in my project which derives from the originalChildNodeSelectionPageController
so that theMaster
model still gets passed back to the view. 当所有页面都使用相同的文档类型(ChildNodeSelectionPage
)时,这一切都很好,但是现在我已更改主页,以使用此文档类型的派生形式(CustomChildNodeSelectionPage
)作为附加属性,并且不得不创建一个虚拟控制器(我的项目中的CustomChildNodeSelectionPageController
)是从原始ChildNodeSelectionPageController
派生的,因此Master
模型仍然可以传递回视图。This part also seems to work fine (based upon breakpoints being hit in the original controller) but the problem happens when the view is hit: now, for some unknown reason,
Model.Content.Site().Children
has a count of 0 when on the Home page but yet, if navigating to the URL of any of the child pages it's 2 (as expected). 这部分似乎也可以正常工作(基于在原始控制器中命中的断点),但是当视图被命中时就会发生问题:现在,由于某种未知的原因,Model.Content.Site().Children
的计数为0在首页上,但是,如果导航到任何子页面的URL,则为2(按预期)。Also note that the Home Document still uses the
ChildNodeSelectionPage.cshtml
Template even though its Document Type has now been changed to use "Custom Child Node Selection Page"). 另请注意,即使现在已将其文档类型更改为使用“自定义子节点选择页面”,主文档仍然使用ChildNodeSelectionPage.cshtml
模板。Master.cshtml (note: irrelevant code omitted for brevity) Master.cshtml (注意:为简洁起见,省略了不相关的代码)
@inherits Umbraco.Web.Mvc.UmbracoViewPage<Web.Portal.Models.Master> <!DOCTYPE html> <html> <body> @Html.Partial("Navigation Menu") @RenderBody() </body> </html>
Navigation Menu.cshtml 导航Menu.cshtml
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @using Umbraco.Web @using Umbraco.Web.Models @helper AddMenuItems(IEnumerable<IPublishedContent> menuItems) { if (menuItems.Any()) { <ul> @foreach (var menuItem in menuItems) { <li> @if (menuItem.Id == UmbracoContext.PageId) { @menuItem.Name } else { <a href="@menuItem.Url" title="@menuItem.GetPropertyValue("description")">@menuItem.Name</a> } @AddMenuItems(menuItem.Children) </li> } </ul> } } //NOTE: This is where the problem is when called from the `CustomChildNodeSelectionPage`. @AddMenuItems(Model.Content.Site().Children)
ChildNodeSelectionPage.cshtml ChildNodeSelectionPage.cshtml
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ Layout = "Shared/Master.cshtml"; } //NOTE: Irrelevant code omitted for brevity.
ChildNodeSelectionPageController ChildNodeSelectionPageController
public class ChildNodeSelectionPageController : RenderMvcController { private ActionResult Index(IPublishedContent content, CultureInfo currentCulture) => CurrentTemplate ( new Master ( content, currentCulture, new Company(0, "ACME"), new[] { new Company(0, "ACME"), new Company(1, "Jimbo Jones' Jimbo Burgers Inc.") }, "Jiminy Jilikers" ) ); public override ActionResult Index(RenderModel model) => Index ( model.Content, model.CurrentCulture ); }
CustomChildNodeSelectionPageController CustomChildNodeSelectionPageController
//Exists only so that the new Document Type can call Index on ChildNOdeSelectionPageController. public class CustomChildNodeSelectionPageController : ChildNodeSelectionPageController { }
So it turns out all I had to do was manually republish ("Save and Publish" button on "Content") every page through the CMS and it magically started working again! 因此,事实证明,我要做的就是通过CMS在每个页面上手动重新发布(“内容”上的“保存并发布”按钮),并且神奇地再次开始工作! Prior to this issue, I did have to change the Content Type of the root page via the database which seemed to create a few problems (of which I'm guessing this was one of them). 在此问题之前,我确实必须通过数据库更改根页面的内容类型,这似乎会产生一些问题(我猜这是其中的一个)。
If anyone's interested, I got the idea to republish from here: https://our.umbraco.com/forum/templating/templates-and-document-types/4585-Change-document-type 如果有人感兴趣,我有个主意可以从此处重新发布: https : //our.umbraco.com/forum/templating/templates-and-document-types/4585-Change-document-type
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.