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?
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
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><a href="@node.Url">@node.Name</a></li>
}
Any ideas what i am doing wrong.
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
Its returns nothing but the node contains 3-4 subnodes
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.?
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>
}
}
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
is working on a reply...