Computer Magic Logo
Get content by id

Monday, February 15, 2016

Published by Aristotelis Pitaridis

We can use the Umbraco.Content() member function in order to get the node by it's id.

var MyContent = Umbraco.Content(1111);

The previous line of code works in a View but if we want to get the nodeĀ in a class then we have to use the following code snippet.

var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
IPublishedContent MyContent = umbracoHelper.TypedContent(1111);