Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jonas Eriksson 930 posts 1825 karma points
    Feb 15, 2011 @ 20:28
    Jonas Eriksson
    0

    DynamicNode safe property? (topnavigation in Razor)

    Hi!

    I'm playing with DynamicModel in Razor and cant figure out how to get a safe property. Here's a rather compact script for a top navigation. In the loop I'd like to add a condition to exclude by umbracoNaviHide's. However that's not so easy to do if I'm not sure all children has that property - since c.umbracoNaviHide will cast an error for nodes without that property. I'm pretty sure this will be addressed in 4.6.2. But I might just as well miss something, and there's a safe get property value available for DynamicNode?

    @{
      var currentPage = Model;
      while (currentPage.Level>2) currentPage=Model.Parent;
      
      <ul class="topnavigation">
      @foreach (var c in currentPage.Children)
      {
       <li><a href="@c.Url">@c.Name</a></li>
       }
      </ul>
      
      }

    Cheers

    Jonas

Please Sign in or register to post replies

Write your reply to:

Draft