Umbraco 7 + Razor: How to get a Document/Node by ID?

Aximili picture Aximili · Sep 5, 2014 · Viewed 22.2k times · Source

In the sample code, this is how you get the Home page from a .cshtml file

var homePage = CurrentPage.AncestorsOrSelf(1).First();

Now, how do I get a specific page/node (not related to current page, eg. the News page) by its ID?

Answer

Digbyswift picture Digbyswift · Sep 5, 2014

You can use exactly the same approach but use .Where(x => x.Id == newsPageId).

Alternatively, you can use @Umbraco.TypedContent(newsPageId) or @Umbraco.Content(newsPageId).