Child nodes not inside parent

I have a stored procedure which returns the data for the menu:



Then in my controller I do this:



And in the view



But when I start the project, I got something like this:



The child nodes are not inside their parents. There must be something I'm missing.

Thanks.
Bernard.

1 Reply

SK Shanmugaraja K Syncfusion Team September 17, 2018 11:40 AM UTC

Hi Bernard, 
 
Thank you for using Syncfusion products. 
 
We have checked your reported problem and provided code block at our end. The reported problem occurs due to using the child field for dataSource. If specify the child field in datasource, we have considered this data as a hierarchical data, but in your application you have binded the self-referential dataSource. So kindly modify the name to resolve your reported problem. 
 
 
listdata.Add(new TreeViewItemModel 
{ 
                id = m.Id, 
                pid = m.ParentId, 
                name = m.Text,  
                HasChild = m.Child,  // don’t provide the data field name as child 
}); 
 
          //Mapping fields 
  
          fields.DataSource = listdata; 
          fields.HasChildren = "HasChild"; 
          fields.Id = "id"; 
          fields.ParentID = "pid"; 
          fields.Text = "name"; 
          ViewBag.TreeViewFields = fields; 
 
 
 
For this scenario, we have bind the list data to render the TreeView component. Please find the sample in below location. 
 
 
Regards, 
Shanmugaraja K 


Loader.
Up arrow icon