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

4 posts, 0 answers
  1. Anton
    Anton avatar
    3 posts
    Member since:
    Oct 2014

    Posted 05 Nov 2014 Link to this post

    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.
  2. Anton
    Anton avatar
    3 posts
    Member since:
    Oct 2014

    Posted 05 Nov 2014 in reply to Anton Link to this post

    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.
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 07 Nov 2014 Link to this post

    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.

     
  5. Anton
    Anton avatar
    3 posts
    Member since:
    Oct 2014

    Posted 07 Nov 2014 in reply to Alex Gyoshev Link to this post

    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.
Back to Top
UI for ASP.NET MVC is VS 2017 Ready