z488758
asked on
DynaTree and Ajax Loading
Hi
ASP.NET MVC 4, I am trying to use Dynatree, loading data via an Ajax call
Simple code follows. The Ajax call is getting three records, but nothing is making it to the treeview. Any help would be appreciated
<script type="text/javascript">
$(function () {
$("#tree").dynatree({
initAjax: {
url: "/Maintenance/_AjaxGetActi veCategori es",
data: { key: "root",
mode: "all"}
}
});
});
</script>
</head>
<body class="example">
<h1>Example: Init from Ajax request</h1>
<p class="description">
This sample initializes the IC tree from a JSON request.
</p>
<!-- Add a <div> element where the tree should appear: -->
<div id="tree"> </div>
//================== Ajax
public ActionResult _AjaxGetActiveCategories([ DataSource Request]Da taSourceRe quest request)
{
TestDatabaseEntities db = new TestDatabaseEntities();
var categories = (from x in db.Categories
select x).ToList();
DataSourceResult result = categories.ToDataSourceRes ult(reques t);
return Json(result,JsonRequestBeh avior.Allo wGet);
}
ASP.NET MVC 4, I am trying to use Dynatree, loading data via an Ajax call
Simple code follows. The Ajax call is getting three records, but nothing is making it to the treeview. Any help would be appreciated
<script type="text/javascript">
$(function () {
$("#tree").dynatree({
initAjax: {
url: "/Maintenance/_AjaxGetActi
data: { key: "root",
mode: "all"}
}
});
});
</script>
</head>
<body class="example">
<h1>Example: Init from Ajax request</h1>
<p class="description">
This sample initializes the IC tree from a JSON request.
</p>
<!-- Add a <div> element where the tree should appear: -->
<div id="tree"> </div>
//================== Ajax
public ActionResult _AjaxGetActiveCategories([
{
TestDatabaseEntities db = new TestDatabaseEntities();
var categories = (from x in db.Categories
select x).ToList();
DataSourceResult result = categories.ToDataSourceRes
return Json(result,JsonRequestBeh
}
ASKER
Thanks for your comments / assistance.
I am relatively inexperienced, so please bear with me
(a) I don't know how to interrogate the data. I can see the RESULT in the controller, which is the data in the list. I do not know how to see it when it returns as JSON ??
(b) Not sure what the comment "do you have a link to see your page" means? I can see the page that I am drawing the treeview on which is simply a treeview with no nodes
(c) It won't be mapped as you say. I am wanting to get the data from a database, an ajax call that returns as json, I am not sure how you map it. However, I do only want the root nodes., assuming will use lazy loading to load the children when selected
Sorry if my responses are a bit "ignorant"
I am relatively inexperienced, so please bear with me
(a) I don't know how to interrogate the data. I can see the RESULT in the controller, which is the data in the list. I do not know how to see it when it returns as JSON ??
(b) Not sure what the comment "do you have a link to see your page" means? I can see the page that I am drawing the treeview on which is simply a treeview with no nodes
(c) It won't be mapped as you say. I am wanting to get the data from a database, an ajax call that returns as json, I am not sure how you map it. However, I do only want the root nodes., assuming will use lazy loading to load the children when selected
Sorry if my responses are a bit "ignorant"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
1. it is a development project so not published, just on development machine not publicly visible
2. Thanks for pointing to how to see data, it is as follows. I have no idea how to map to a format dynatree is happy with?
{"Data":[{"Id":1,"Name":"M otor Vehicle","SourceId":0,"Ent ityState": 2,"EntityK ey":{"Enti tySetName" :"Categori es","Entit yContainer Name":"Tes tDatabaseE ntities"," EntityKeyV alues":[{" Key":"Id", "Value":1} ],"IsTempo rary":fals e}},{"Id": 2,"Name":" Personal Indemnity","SourceId":0,"E ntityState ":2,"Entit yKey":{"En titySetNam e":"Catego ries","Ent ityContain erName":"T estDatabas eEntities" ,"EntityKe yValues":[ {"Key":"Id ","Value": 2}],"IsTem porary":fa lse}},{"Id ":3,"Name" :"Category 3","SourceId":0,"EntitySta te":2,"Ent ityKey":{" EntitySetN ame":"Cate gories","E ntityConta inerName": "TestDatab aseEntitie s","Entity KeyValues" :[{"Key":" Id","Value ":3}],"IsT emporary": false}}]," Total":3," AggregateR esults":nu ll,"Errors ":null}
1. it is a development project so not published, just on development machine not publicly visible
2. Thanks for pointing to how to see data, it is as follows. I have no idea how to map to a format dynatree is happy with?
{"Data":[{"Id":1,"Name":"M
Open in new window
?
Do you have a link to see your page?