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();
});
});
Karthik ElumalaiPosted Jun 16, 2016, 1:21 PM
Posted Jun 16, 2016, 6:04 AM
Vinay SinghPosted Jun 16, 2016, 5:18 AM