I just burned up 10 hours of a 100 hour budget trying to get the tree view to bind to an XML file. None of your examples worked! So then I tried the remote binding, which did actually work, as long as I transformed the XML into a class for the JSON return. Well, I can deal with transforming the XML document into a class, but the hierarchical part does not work at all. The tree just repeats the original root items over and over again.
I am including code for the classes that I am trying to use, which includes the base class and a second class with would be the second tier (I won't actually need 2 classes in the end). I have also included the controller code and the view code.
Please, please help, my time is running low and I promised to get this done using your stuff!!!!!
Here is the tree result. As you can see the root items are just repeated over and over. The item that is a child of "you" never shows up
you
My Classes
My Controller
My View
I am including code for the classes that I am trying to use, which includes the base class and a second class with would be the second tier (I won't actually need 2 classes in the end). I have also included the controller code and the view code.
Please, please help, my time is running low and I promised to get this done using your stuff!!!!!
Here is the tree result. As you can see the root items are just repeated over and over. The item that is a child of "you" never shows up
you
-
you
-
you
-
you
-
you
-
you
-
you
-
me
-
-
me
-
-
me
-
-
me
-
-
me
-
-
me
me
My Classes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MCFD.MobilePolicy.MVC.Models
{
public class SiteStructure
{
public SiteStructure()
{
}
private List<
string
> next;
private string myName = "N/A";
private List<
InnerStructure
> colHasChildren;
private int ID;
// Declare a Name property of type string:
public string Name
{
get
{
return myName;
}
set
{
myName = value;
}
}
public int id
{
get
{
return ID;
}
set
{
ID = value;
}
}
//public bool HasChildren
//{
// get
// {
// return hasChildren;
// }
// set
// {
// hasChildren = value;
// }
//}
public List<
InnerStructure
> hasChildren
{
get
{
return colHasChildren;
}
set
{
colHasChildren = value;
}
}
}
public class InnerStructure
{
public InnerStructure()
{
}
private List<
string
> next;
private string myName = "N/A";
private List<
InnerStructure
> colHasChildren;
private int ID;
// Declare a Name property of type string:
public string Name
{
get
{
return myName;
}
set
{
myName = value;
}
}
public int id
{
get
{
return ID;
}
set
{
ID = value;
}
}
//public bool HasChildren
//{
// get
// {
// return hasChildren;
// }
// set
// {
// hasChildren = value;
// }
//}
public List<
InnerStructure
> hasChildren
{
get
{
return colHasChildren;
}
set
{
colHasChildren = value;
}
}
}
}
My Controller
public JsonResult Employees(int? id)
{
//ulitimate goal is to transform this xml into a structure for the tree. I will deal with this later. Note that none of the bind to xml methods have worked for me.
XElement xml = XElement.Load(Server.MapPath("~/App_Data/books.xml"));
//Create 2 items for the tree
Models.SiteStructure sitemapitem = new Models.SiteStructure();
sitemapitem.Name = "you";
sitemapitem.id = 1;
Models.SiteStructure sitemapitem2 = new Models.SiteStructure();
sitemapitem2.Name = "me";
sitemapitem2.id = 2;
//Create hierarchy by adding a new list to the first item in the root of items
Models.InnerStructure sitemapitem3 = new Models.InnerStructure();
sitemapitem3.Name = "why does this not work?";
sitemapitem3.id = 3;
List<
Models.InnerStructure
> sitemap2 = new List<
Models.InnerStructure
>();
sitemap2.Add(sitemapitem3);
sitemapitem.hasChildren = sitemap2;
//Add the items to list of items to return
List<
Models.SiteStructure
> sitemap = new List<
Models.SiteStructure
>();
sitemap.Add(sitemapitem);
sitemap.Add(sitemapitem2);
return Json(sitemap, JsonRequestBehavior.AllowGet);
}
My View
<
div
class
=
"demo-section"
>
@(Html.Kendo().TreeView()
.Name("treeview")
.DataTextField("Name")
.DataSource(dataSource => dataSource
.Read(read => read
.Action("Employees", "SiteEditor")
)
)
)
</
div
>