Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Sometimes website have a lot of root nodes, in multilingual case for example.
In common, there is no problem to get a current root node with @Model.Ancestor<HomePage>(), but there is when you do it in a partial view of nested content
How to get a current root node from partial view of nested content?
You can get the current page Id with this code:
And then get current root node with code:
var currentPage = Umbraco.TypedContent(UmbracoContext.Current.PageId);
var root = currentPage.Ancestor<HomePage>();
Thank you, seems it what I need.
Is it optimal performance way, or has some leaks?
It's fine in performance
Would it not be better to use:
var currentNode = UmbracoContext.Current.PublishedContentRequest.PublishedContent;
var root = currentNode.Site();
Alternative access IPublishedContent via UmbracoHelper - Umbraco property in UmbracoViewPage class.
var currentNode = Umbraco.AssignedContentItem.Root();
var site = currentNode.Root();
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted