title: Umbraco 7 Razor - find parent
body: <p>I'm using Umbraco 7 and I want a partial view to render a left nav starting at a certain point up the tree where it finds a page with a certain property set.</p>
  
  <p>I've tried this but it only works from a fixed depth 1 layer down in the tree. I want to do this from any depth within the site and have it recurse back up until it finds an item and have that be the root for the left nav.</p>
  
  <pre><code>@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
  
  @{
      @* Get the item above this one that has a property of resetLeftNav ticked *@
      var root = CurrentPage.AncestorOrSelf(1).Children.Where("resetLeftNav").First(); 
  }
  
  &lt;ul class="nav left-nav"&gt;
      @foreach(var page in root.Children)
      {
          &lt;li class=""&gt;
              &lt;a href="@page.Url"&gt;@page.Name&lt;/a&gt;
          &lt;/li&gt;
      }
  &lt;/ul&gt;
  </code></pre>