Umbraco Razor - One Way to Check to See if A Node or Page Still Exists and or is Published

This can be used, for example, in a Partial View to see if a node is publish and or exists to ensure that the page does not throw an error when trying to write out details from a page or it's sub nodes .

var thisPage = Umbraco.Content(1256); // Get the page

@if(thisPage.Path != null && thisPage.Path != "")
   // Write out content from that page



Popular posts from this blog

Umbraco 7 - C# Razor - Passing a parameter variable from a Template to a Partial View.

Umbraco 7 Hide a page from Navigation or Sub Navigation with umbracoNaviHide using Razor in a template or partial view

Umbraco Razor Sort Nodes Ascending or Descending