episerver- iContentLoader在过滤开始页面时返回不同的页面类型

发布于 2025-01-21 11:49:16 字数 496 浏览 4 评论 0原文

我正在尝试在剃须刀代码中获取启动页面,以便我可以根据开始页面显示不同的NAV。这就是我的操作方式:

var contentLoader = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentLoader>();
var pages = contentLoader.GetChildren<PageData>(ContentReference.StartPage);

这是在调试器中显示的内容。我期望只看到类型,开始。但是我看到了英雄页面和所有内容。有什么想法在这里发生了什么?

I'm trying to get the start pages in Razor code so I can display different navs based on the start page. Here's how I'm doing it:

var contentLoader = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentLoader>();
var pages = contentLoader.GetChildren<PageData>(ContentReference.StartPage);

This is what shows up in the debugger. I was expecting to only see pages of type, Start. But I'm seeing Hero pages and everything. Any ideas what's going on here?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ま柒月 2025-01-28 11:49:16

如果您想获取开始页面(仅一个实例),并且它是在管理模式下以启动页面为单位的开始页面以用于您网站的配置,则应执行以下操作

var startPage = contentLoader.Get<StartPage>(ContentReference.StartPage);

If you want to get the start page (just one instance) and it is the same start page that is selected as start page in admin mode for the configuration of your site you should do the following

var startPage = contentLoader.Get<StartPage>(ContentReference.StartPage);
纵情客 2025-01-28 11:49:16

我能够通过传递根本页面的ContentReference和我的开始页面对象来解决此问题。

var pages = contentLoader.GetChildren<namespace.StartPage>(ContentReference.RootPage);

I was able to resolve this by passing in the ContentReference for the root page and my start page object.

var pages = contentLoader.GetChildren<namespace.StartPage>(ContentReference.RootPage);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文