Matthew Alexandros
01/26/2024, 12:14 PMJemayn
01/26/2024, 12:31 PMCurrentPage
property which is an IPublishedContent, so based on that you could navigate to the site node.
From fx an ApiController you would have no context, so the spot you call the api controller from would often pass along fx a current node id to the api controller to get the node and then navigate fromMatthew Alexandros
01/26/2024, 12:44 PMJemayn
01/26/2024, 12:52 PMModel
variable.
So a common way to do this if you use modelsbuilder models would be to navigate up the tree to the correct model like this:
csharp
var site = Model.AncestorOrSelf<ContentModels.Site>();
or without modelsbuilder:
csharp
var site = Model.AncestorOrSelf("site");
Assuming your root node is of the type "Site", otherwise it should of course be adapted to your caseMatthew Alexandros
01/26/2024, 1:08 PMA hub and casual space for you to interact with fellow community members and learn more about Umbraco!
Powered by