TreeView with Remote Databinding example using Id that is a string

2 posts, 1 answers
  1. Carrie
    Carrie avatar
    27 posts
    Member since:
    Aug 2013

    Posted 18 Sep 2013 Link to this post

    Hello,

    I am trying to implement a TreeView using remote binding.  My datasource Id property is actually a string not an integer - I am having trouble getting this working - can you advise where I am going wrong?    My code is below.

    Thanks,
    Carrie

    View
    @(Html.Kendo().TreeView()
         .Name("treeviewTierQueue")
         .DataTextField("Text")
         .DataSource(dataSource => dataSource
                  .Read(read => read.Action("GetTierQueueList", "Enum"))
      ))
    Controller
    public JsonResult GetTierQueueList(string level)
    {
        var items = new List<NestedSelectListItem>()
            {
                new NestedSelectListItem {Id = "0", Text = "All Analysts"},
                new NestedSelectListItem {Id = "1", Text = "All Groups"},
                new NestedSelectListItem {
                    Id = "2",
                    Text = "Service Desk",
                    hasChildren=true,
                    Items = new List<NestedSelectListItem> ()
                    {
                        new NestedSelectListItem {Id = "2a", Text = "2nd Level"},
                        new NestedSelectListItem {Id = "2b", Text = "2nd Level B"},
                        new NestedSelectListItem {
                            Id = "2c",
                            Text = "2nd Level C",
                            hasChildren= true,
                            Items = new List<NestedSelectListItem> ()
                            {
                                new NestedSelectListItem {Id = "3a", Text = "3rd Level"},
                                new NestedSelectListItem {Id = "3b", Text = "3rd Level B"}
                            }
                      } } }
            };
     
        if (!String.IsNullOrEmpty(level))
        {
            var filtered = items.First(i => i.Id == level).Items;
            items = filtered;
        }
     
        return Json(items.AsEnumerable(), JsonRequestBehavior.AllowGet);
    }

  2. Answer
    Carrie
    Carrie avatar
    27 posts
    Member since:
    Aug 2013

    Posted 19 Sep 2013 Link to this post

    I resolved the issue by renaming the passed in parameter from "level" to "Id".

    Thanks,
    Carrie
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top