This project is read-only.

Building a TreeNode structure

Jun 14, 2012 at 4:42 PM
Edited Jun 14, 2012 at 4:43 PM

I'm trying to build a TreeNode structure. I need to build this in a seperate class library and send it back. to my MVC razor page for rendering.

I can create multiple separate TreeNodes, which .GetHtml() works fine- however the problem im having is when adding a tree node to another as a child. I get a null reference- and cannot figure out what i'm doing wrong.

Code:

// Build the navigatable nodes
DNA.Mvc.NavigatableNode TreeViewNode = new DNA.Mvc.NavigatableNode("Node", (string)@"Value1")
{
    ImageUrl = "http://www.dotnetage.com/content/images/ok.gif",
    NavigateUrl = "http://www.dotnetage.com/sites/djme/demos.html",
    Target = "http://www.dotnetage.com/sites/djme/demos.html",
    ToolTip = "Tip"
};

DNA.Mvc.NavigatableNode TreeViewNode2 = new DNA.Mvc.NavigatableNode("Node 2", (string)@"Value2")
{
    ImageUrl = "http://www.dotnetage.com/content/images/ok.gif",
    NavigateUrl = "http://www.dotnetage.com/sites/djme/demos.html",
    Target = "http://www.dotnetage.com/sites/djme/demos.html",
    ToolTip = "Tip"
}; 
            
// Convert into tree nodes
DNA.Mvc.jQuery.TreeNode tempNode = new DNA.Mvc.jQuery.TreeNode(TreeViewNode);
DNA.Mvc.jQuery.TreeNode tempNode2 = new DNA.Mvc.jQuery.TreeNode(TreeViewNode2);
            
// Generate seperate HTML
Console.WriteLine(tempNode.GetHtml());
Console.WriteLine(tempNode2.GetHtml());

// Add node 2 as child node of node 1
tempNode.Children.Add(tempNode2);

// Generate the html of node 1, which now has a child node, node 2
Console.WriteLine(tempNode.GetHtml()); 

The stack trace of the null ref exception is:

   at DNA.Mvc.jQuery.TreeNode.RenderBeginTag(HtmlTextWriter writer)
   at DNA.Mvc.ViewComponent.Render(HtmlTextWriter writer)
   at DNA.Mvc.ViewComponent.GetHtml()

Can anyone help me?