I have just added jqTree to my ASP MVC app. I need to display a TreeView in my view:
@{
ViewBag.Title = "Tree";
}
<h2>@ViewBag.Title</h2>
<div id="tree1" data-url="/Home/Nodes"></div>
@section scripts {
<script language="javascript" type="text/javascript">
$(function () {
$('#tree1').tree();
});
</script>
}
My data is in a JSON file (~/App_Data/Roles.json):
{
"id": 1,
"label": "Role1",
"children": [
{
"id": 2,
"label": "Role2",
"children": [
{
"id": 3,
"label": "Role3",
"children": [
]
},
{
"id": 4,
"label": "Role4",
"children": [
]
}
]
}
]
}
How do I load the json file in the controller action method to display corresponding TreeView in the view?
public ActionResult Nodes()
{
var roles = // load json file
return Json(roles, JsonRequestBehavior.AllowGet);
}