Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5181
  • Last Modified:

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/_AjaxGetActiveCategories",            
                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([DataSourceRequest]DataSourceRequest request)
        {
            TestDatabaseEntities db = new TestDatabaseEntities();

            var categories = (from x in db.Categories                        
                             select x).ToList();

            DataSourceResult result = categories.ToDataSourceResult(request);

            return Json(result,JsonRequestBehavior.AllowGet);
        }
0
z488758
Asked:
z488758
  • 2
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
Could you confirm /Maintenance/_AjaxGetActiveCategories return something like :

[
    {"title": "Item 1"},
    {"title": "Folder 2", "isFolder": true, "key": "folder2",
        "children": [
            {"title": "Sub-item 2.1"},
			{"title": "Sub-item 2.2"}
			]
        },
	{"title": "Folder 3", "isFolder": true, "key": "folder3",
	    "children": [
		    {"title": "Sub-item 3.1"},
		    {"title": "Sub-item 3.2"}
		    ]
		},
	{"title": "Item 5"}
]

Open in new window


?

Do you have a link to see your page?
0
 
z488758Author Commented:
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"
0
 
leakim971PluritechnicianCommented:
a) I don't know how to interrogate the data.
try to put the URL in your web browser :

http://www.yourdomain.com/Maintenance/_AjaxGetActiveCategories

b) Not sure what the comment "do you have a link to see your page" means?

What is the URL of your website over Interne so I can put it in my webbrowser to see your page
0
 
z488758Author Commented:
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":"Motor Vehicle","SourceId":0,"EntityState":2,"EntityKey":{"EntitySetName":"Categories","EntityContainerName":"TestDatabaseEntities","EntityKeyValues":[{"Key":"Id","Value":1}],"IsTemporary":false}},{"Id":2,"Name":"Personal Indemnity","SourceId":0,"EntityState":2,"EntityKey":{"EntitySetName":"Categories","EntityContainerName":"TestDatabaseEntities","EntityKeyValues":[{"Key":"Id","Value":2}],"IsTemporary":false}},{"Id":3,"Name":"Category 3","SourceId":0,"EntityState":2,"EntityKey":{"EntitySetName":"Categories","EntityContainerName":"TestDatabaseEntities","EntityKeyValues":[{"Key":"Id","Value":3}],"IsTemporary":false}}],"Total":3,"AggregateResults":null,"Errors":null}
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now