Copied to clipboard

Flag this post as spam?

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


  • Mr A 216 posts 278 karma points
    Oct 17, 2011 @ 11:02
    Mr A
    0

    Separate menus for each page

    Hi , I am trying to display separate menus on each page by just including the code below , but it comes up withn an error :

    Error loading Razor Script ~/macroscripts/contentsubmenu.cshtml
    Object reference not set to an instance of an object.

    @foreach (var node in Model.AncestorOrSelf(1).Children.Where("NodeTypeAlias == \"Misc\"").First().Children(){

        <li><href="@node.Url">@node.Name</a></li>
    }

     

    Any ideas what i am doing wrong.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 17, 2011 @ 11:30
    Dirk De Grave
    0

    i'm suspecting that .First() is throwing the error as it doesn't find any children of type "Misc". Have you tried adding a Count to verify whether some/any of your statements return any nodes?

     

    Cheers,

    /Dirk

  • Mr A 216 posts 278 karma points
    Oct 17, 2011 @ 11:45
    Mr A
    0

    Its returns nothing but the node contains 3-4 subnodes

  • Anthony pj 40 posts 63 karma points
    Oct 17, 2011 @ 12:30
    Anthony pj
    0

    I tried out your code in a dummy project of my own ....

    1. First I tried using changing node alias to document type my own and removing  .First().Children()

     Model.AncestorOrSelf(1).Children.Where("NodeTypeAlias == \"TextPage\""))

    This returned a list of links of documents type TextPage under the root node .. as expected

    2. Then tried

    Model.AncestorOrSelf(1).Children.Where("NodeTypeAlias == \"TextPage\"").First().Children())

    Knowing i had no children under nodetypealias TextPage this retuinr the error

    Error loading Razor Script 
    Cannot invoke a non-delegate type

    3. Then tried

    Model.AncestorOrSelf(1).Children.Where("NodeTypeAlias == \"Misc\""))

    I have no type "Misc"... No Error was returned

    4. Using your full statement

    Model.AncestorOrSelf(1).Children.Where("NodeTypeAlias == \"Misc\"").First().Children())

    returned the error notifcation you were experiencing...

    5. The knowing i had a type productlist under list with child records product with child records product review used

    Model.AncestorOrSelf(1).Children.Where("NodeTypeAlias == \"ProductList\"").First().Children())

    returnee the error Cannot invoke a non-delegate type

    Conclusion :

    Looks liek you have no type Misc and that even if you did this (for me as least) structure would return an error.?




  • Mr A 216 posts 278 karma points
    Oct 17, 2011 @ 13:21
    Mr A
    0

    Hi , thnx for looking into this issue , I tried the following which is working fine but it doesnt looks like an elegant solution :

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{

       foreach (var c in Model.NodeById(1074).Descendants())

        {

      <li> <a href="@c.Url">@c.Name</a></li>

       }

     }

    Where nodeid for misc is 1074 , dunno why using Model.AncestorOrSelf(1).Children.Where("NodeTypeAlias == \"Misc\"")) is working on your machine and not  working on mine
  • Anthony pj 40 posts 63 karma points
    Oct 17, 2011 @ 13:52
    Anthony pj
    0

    The Following appears to return results you are after

     foreach (var nodes in Model.AncestorOrSelf(1).ProductList)
      {
      foreach (var items in nodes.Down().Children)
      
         <li><a href="@items.Url">@items.Name</a></li>
       }
      }
      
      }

     

    My Structure is

    Home

      ProductList

           ProductsA

              ProductReviewAA

              ProductReviewAB

          ProductsB

             ProductReviewBA

             ProductReviewBB

     

    Above code returns

          ProductReviewAA

         ProductReviewAB

     

    Iam using ProductList where you would use Misc , otherwise .Children.Where("NodeTypeAlias == \"Misc\"") works equally as well

     

    Good Luck

     


Please Sign in or register to post replies

Write your reply to:

Draft