Copied to clipboard

Flag this post as spam?

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


  • Jimmy Dan Mortensen 77 posts 197 karma points
    Jan 23, 2012 @ 15:08
    Jimmy Dan Mortensen
    0

    Model.NodeById(Model.Contentpicker)

    Hi Guys

    I'm trying to create a navigational loop, that shows all the children of the node I've selected in a content-picker

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
      var parent = @Model.trailerSubNavi;
      var node = @Model.NodeById("parent");
       
    <h3>@Model.Name</h3>
        <ul class="subNav">
          @foreach (var side2 in node.Children.Where("Visible")){
            <li>
              <a href="@side2.Url">@side2.Name</a>
            </li>
          }          
        </ul>
    }

     

    But I'm getting the error:

    Error loading Razor Script SubNavTrailerModeller.cshtml
    Cannot instantiate a DynamicNode without an id

    I've tried multiple things, but apparently not the right one - Any help would be greatly appreciated, as I really don't wanna hard-code the Id.

    Best regards
    Jimmy Dan Mortensen

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 23, 2012 @ 15:10
    Jeroen Breuer
    0

    If parent is an id this should work:

    var node = @Model.NodeById(parent);

    Jeroen

  • Jimmy Dan Mortensen 77 posts 197 karma points
    Jan 23, 2012 @ 15:12
    Jimmy Dan Mortensen
    0

    dah ... I've been starring at this for 30 minutes now not seeing what the f*** I was doing wrong :-)

    Thank you for pointing out the obvious ;-)
    Jimmy

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Jan 24, 2012 @ 14:14
    Dan Diplo
    0

    Not wishing to be a pedant, but the prefered way in 4.7.1 and up is to use @Library.NodeById in preference to @Model.NodeById. The two do the exact same thing, it's just that the latter has been deprecated in favour of the former (due to the fact that it's more logical to separate node retrieval from the Model).

Please Sign in or register to post replies

Write your reply to:

Draft