Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1215
Infragistics tree with unlimited hierarchy levels in ASP.NET MVC
posted

How do you code the Infragistics tree for unlimited levels of hierarchy? I.e. sub-nodes under sub-nodes under sub-nodes, etc.

Desired result:

Main node 1

    - Sub node 1

    - Sub node 2

        - Sub-sub node 1

            - Sub-sub-sub node

    - Sub node 3, etc.

Here is my model class. Notice the "ChildItems" list inside it.

public class TreeListItem : ICloneable, IComparable, IComparable<TreeListItem>
{
    public string Text { get; set; }
    public object Value { get; set; }
    public string Base64ImageUrl { get; set; } = "";
    public List<TreeListItem> ChildItems = new List<TreeListItem>();
}

Here is my MVC view code, which only shows the first level without any child items.

@(Html.Infragistics().Tree()
.ID("FilterTree")
.Bindings(b1 =>
{
b1
.ValueKey("Value")
.TextKey("Text")
.ImageUrlKey("Base64ImageUrl")
.ChildDataProperty("ChildItems");
})
.DataSource(Model.TreeListItems)
.DataBind()
.Render()
)

This also did not show any child items:

@(Html.Infragistics().Tree()
.ID("FilterTree")
.Bindings(b1 =>
{
b1
.ValueKey("Value")
.TextKey("Text")
.ImageUrlKey("Base64ImageUrl")
.ChildDataProperty("ChildItems")
.Bindings(b2 =>
b2
.ValueKey("Value")
.TextKey("Text")
.ImageUrlKey("Base64ImageUrl")
.ChildDataProperty("ChildItems")
);
})
.DataSource(Model.TreeListItems)
.DataBind()
.Render()
)