I am trying to bind my kendo treeview to a sql self referencing table that stores the data needed to represent a multi-level hierarchy of treeview items. I am attaching a picture of my sql table as well as a screen shot of how my treeview is currently displaying this data, and certain items are being duplicated, and I can't determine why. Below is the code for my controller and view. Pretty sure my table structure is correct, but I'm thinking the query is adding the children nodes a 2nd time but as parent items, so maybe the controller needs to filter out the items that don't have null as the parent ID as it's binding the parent nodes... If anyone can help I'd be very grateful!!!
Controller
public class NavigationMenuItemController : Controller
{
private symphonyappEntities db = new symphonyappEntities();
// GET: /NavigationMenuItem/
public ActionResult Index()
{
var navigationmenuitems = db.NavigationMenuItems.Include(n => n.NavigationMenuItem1).Include(n => n.NavigationMenu);
return PartialView("~/Views/Shared/_NavigationBarPartial.cshtml", navigationmenuitems);
}
[ChildActionOnly]
public ActionResult NavBarPartial()
{
var navigationmenuitems =
db.NavigationMenuItems.Include(n => n.NavigationMenuItem1).Include(n => n.NavigationMenu);
return PartialView("~/Views/Shared/_NavigationBarPartial.cshtml", navigationmenuitems);
}
}
View
@(Html.Kendo().TreeView()
.Name("treeview")
.HtmlAttributes(new { style = "width:200px;" })
.Events(events => events
.Select("onSelect"))
.BindTo(Model, mappings =>
{
mappings.For<NavigationMenuItem>(binding => binding
.ItemDataBound((item, menuItem) =>
{
item.Text = menuItem.MenuItemText;
item.Id = menuItem.MenuItemURL;
})
.Children(menuItem => menuItem.NavigationMenuItems1));
mappings.For<NavigationMenuItem>(binding => binding
.ItemDataBound((item, submenuitem) =>
{
item.Text = submenuitem.MenuItemText;
item.Id = submenuitem.MenuItemURL;
}));
})
)
Controller
public class NavigationMenuItemController : Controller
{
private symphonyappEntities db = new symphonyappEntities();
// GET: /NavigationMenuItem/
public ActionResult Index()
{
var navigationmenuitems = db.NavigationMenuItems.Include(n => n.NavigationMenuItem1).Include(n => n.NavigationMenu);
return PartialView("~/Views/Shared/_NavigationBarPartial.cshtml", navigationmenuitems);
}
[ChildActionOnly]
public ActionResult NavBarPartial()
{
var navigationmenuitems =
db.NavigationMenuItems.Include(n => n.NavigationMenuItem1).Include(n => n.NavigationMenu);
return PartialView("~/Views/Shared/_NavigationBarPartial.cshtml", navigationmenuitems);
}
}
View
@(Html.Kendo().TreeView()
.Name("treeview")
.HtmlAttributes(new { style = "width:200px;" })
.Events(events => events
.Select("onSelect"))
.BindTo(Model, mappings =>
{
mappings.For<NavigationMenuItem>(binding => binding
.ItemDataBound((item, menuItem) =>
{
item.Text = menuItem.MenuItemText;
item.Id = menuItem.MenuItemURL;
})
.Children(menuItem => menuItem.NavigationMenuItems1));
mappings.For<NavigationMenuItem>(binding => binding
.ItemDataBound((item, submenuitem) =>
{
item.Text = submenuitem.MenuItemText;
item.Id = submenuitem.MenuItemURL;
}));
})
)