am binding tree view based on table in sql server,
i have added column description to my table now i want bind on tree view node click,
i have tried
html helper
@helper GetTreeView(List siteMenu, int parentID)
{
foreach (var i in siteMenu.Where(a => a.ReportsTo.Equals(parentID)))
{
@{var submenu = siteMenu.Where(a => a.ReportsTo.Equals(i.EmpID)).Count();}
@if (submenu > 0)
{
}
else
{
}
@if (submenu > 0)
{
@Treeview.GetTreeView(siteMenu, i.EmpID)
@* Recursive Call for Populate Sub items here*@
}
}
}
controller class
public ActionResult Index()
{
List all = new List();
using (TestDemoEntities dc = new TestDemoEntities())
{
all = dc.tblEmployees.OrderBy(a => a.ReportsTo).ToList();
}
return View(all);
}
view
@if (Model != null && Model.Count() > 0)
{
@Treeview.GetTreeView(Model, Model.FirstOrDefault().ReportsTo)
}
@* Here We need some Jquery code for make this treeview collapsible *@
@section Scripts{
$(document).ready(function () {
$(".treeview li>ul").css('display', 'none'); // Hide all 2-level ul
$(".collapsible").click(function (e) {
e.preventDefault();
$(this).toggleClass("collapse expand");
$(this).closest('li').children('ul').slideToggle();
});
});

Vinay SinghRank #604 · 4K reputationPosted Jun 16, 2016, 1:18 AM EDT
Posted Jun 16, 2016, 2:04 AM EDT
Karthik ElumalaiRank #544 · 4.5K reputationPosted Jun 16, 2016, 9:21 AM EDT