I'm trying to get a path tree of content with the following code - The problem that I seem to have is that @Model is null! What can I do to fix this it's driving me nuts. I just get 'Object reference not set to an instance of an object.' from the macro.
@{ var contentNode = new Node(-1); INode parentNode = @Model.Parent; var nodeTree = new List<Node>(); Node globalRootNode = null; var globalNodeCollection = new List<INode>(); Node globalContentItemNode = null; foreach (var n in contentNode.ChildrenAsList) { if (n.NodeTypeAlias == "GlobalContentContainer") { globalRootNode = new Node(n.Id); globalNodeCollection = globalRootNode.ChildrenAsList; } }
for (int i = 0; i < nodeTree.Count; i++) { foreach (var n in globalNodeCollection) { if (nodeTree[i].Name == n.Name) { globalContentItemNode = new Node(n.Id); globalNodeCollection = n.ChildrenAsList; return; } } } } }
Help! @Model appears to be null!
I'm trying to get a path tree of content with the following code - The problem that I seem to have is that @Model is null! What can I do to fix this it's driving me nuts. I just get 'Object reference not set to an instance of an object.' from the macro.
Can anyone offer me any help?
@using System.Web;
@using umbraco;
@using umbraco.interfaces;
@using umbraco.NodeFactory;
@{
var contentNode = new Node(-1);
INode parentNode = @Model.Parent;
var nodeTree = new List<Node>();
Node globalRootNode = null;
var globalNodeCollection = new List<INode>();
Node globalContentItemNode = null;
foreach (var n in contentNode.ChildrenAsList)
{
if (n.NodeTypeAlias == "GlobalContentContainer")
{
globalRootNode = new Node(n.Id);
globalNodeCollection = globalRootNode.ChildrenAsList;
}
}
while (parentNode != null)
{
nodeTree.Add(new Node(parentNode.Parent.Id));
parentNode = parentNode.Parent;
}
nodeTree.Reverse();
for (int i = 0; i < nodeTree.Count; i++)
{
foreach (var n in globalNodeCollection)
{
if (nodeTree[i].Name == n.Name)
{
globalContentItemNode = new Node(n.Id);
globalNodeCollection = n.ChildrenAsList;
return;
}
}
}
}
}
try without the @
is working on a reply...