This is a migrated thread and some comments may be shown as answers.

Remote Data Binding Not Working with Teleric ASP.NET MVC TreeView Control.

3 Answers 230 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Anton
Top achievements
Rank 1
Anton asked on 05 Nov 2014, 08:31 PM
Please assist. My code is as follows:

Razor:

 @(Html.Kendo().TreeView()
                          .Name("geographyView")
                          .DataTextField("name")
                          .Checkboxes(true)
                          .DataSource(dataSource => dataSource
                                                        .Model(model => model
                                                                            .Id("id")
                                                                            .HasChildren("children")
                                                                            
                                                        ).Read(read => read.Action("Geography", "Home"))
                                                        )
                          )


Controller:

 public JsonResult Geography(long? parentGeographyId)
        {
            if (!parentGeographyId.HasValue)
            {
                ICollection<IGeography2> geography2s = CacheConfig.GeographyCache.FindGeography2();

                var result = geography2s.Select(geography2 => new
                    {
                        geography2.id,
                        geography2.name,
                        children = true
                    }).ToList();

                return Json(result, JsonRequestBehavior.AllowGet);
            }

            if (Convert.ToString(parentGeographyId.Value).Length == 2)
            {
                var geography2Id = (int) parentGeographyId.Value;

                IGeography2 geography2 = _dtoFactory.NewGeography2Dto();

                geography2.id = geography2Id;

                ICollection<IGeography4> geography4s = CacheConfig.GeographyCache.FindGeography4(geography2);

                var result = geography4s.Select(geography4 => new
                    {
                        geography4.id,
                        geography4.name,
                        children = true
                    }).ToList();

                return Json(result, JsonRequestBehavior.AllowGet);
            }

            throw new ArgumentOutOfRangeException("parentGeographyId");
        }

Screenshot is attached.

Basically, the first level of the tree is loaded correctly, and I can see the corresponding AJAX request going out to the controller. However, when I click an entry to expand it in order to fetch the second-level set of entries, nothing happens. The click icon disappears, and no AJAX request is seen going out to the server when viewing the Firefox's Developer Tools' Network tab.

I must be missing something either in the setup of the component (although I do follow Telerik example found here - - or I must be missing a configuration detail such as the version of a supporting component (I am using jQuery 1.9.1 and ASP.NET MVC Q2  2014 SP2).

Thank you in advance for your assistance.

3 Answers, 1 is accepted

Sort by
0
Anton
Top achievements
Rank 1
answered on 05 Nov 2014, 08:51 PM
Believe it or not, renaming children to hasChildren fixed it, in addition to undoing the VS's formatter's having removed redundant field names in the anonymous type in the controller. Telerik, this may be a bug on your part. hasChildren works if specified in the controller, but in cshtml, the impression is as if any name would do.
0
Alex Gyoshev
Telerik team
answered on 07 Nov 2014, 12:46 PM
Hello Anton,

Indeed, the children field is a reserved name for the child datasource of the node, so it cannot be used for passing data.

Regards,
Alex Gyoshev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Anton
Top achievements
Rank 1
answered on 07 Nov 2014, 04:19 PM
Alex, please consider making a list of reserved words prominent in description of each control so that new users can pick it up immediately.

Thanks very much.
Tags
TreeView
Asked by
Anton
Top achievements
Rank 1
Answers by
Anton
Top achievements
Rank 1
Alex Gyoshev
Telerik team
Share this question
or