Copied to clipboard

Flag this post as spam?

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


  • Keith Jackson 183 posts 552 karma points
    Jun 07, 2011 @ 17:13
    Keith Jackson
    0

    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;
                }
            }
        }
      }
    }

  • Eran Meir 401 posts 543 karma points
    Jun 07, 2011 @ 22:50
    Eran Meir
    0

    try without the @

Please Sign in or register to post replies

Write your reply to:

Draft