TreeView Checkbox problems

2 posts, 0 answers
  1. K
    K avatar
    10 posts
    Member since:
    Jan 2013

    Posted 07 Jan 2015 Link to this post

    Currently, your treeview checkbox demo does not match the source code included on the page.  The source code indicates there should be a "Find Checked Nodes" button, but your demo doesn't have this.  When I do a View Source, I see that there is an onCheck script to report what has been checked.  

    In contrast, in my downloaded local demo source code (I am using MVC Q2 2014 SP2), the Find Checked Nodes button exists, but it doesn't do anything.  I am brand new to MVC .NET and jQuery (with some experience with WebForms), so the inconsistencies make things even harder to understand.

    What I WANT to happen is to get the checked values in my HTTPPost controller method, so I can do some database work with the results, but I can't figure out how to get the user checked values there. How can I do this?

    My simplified model:
    public class MyModel
    {
        public string OtherStuff {get; set;}
        public IEnumerable<TreeViewItemModel> treeData { get; set; }
    }

    My simplified view:
    @model MyModel
     
    <text>@Model.SomethingElse</text>
     
        @(Html.Kendo().TreeView()
                .Name("treeview-left")                       
                .ExpandAll(true)
                .Checkboxes(checkboxes => checkboxes
                               .Name("checkedPubIds")
                               .CheckChildren(true)                     
                                )           
                .BindTo(Model.treeData)                      
        )


    My relevant controller methods:
    private MyModel GetMyModel() 
    {           
        var model = new PubTreeModel
            {
              OtherStuff = "Hello",               
              treeData = GetTreeData() // implementation omitted here
            };
                 
        return model;
    }
     
    [HttpGet]
    public ActionResult Index()
    {
        var model = GetMyModel();
        return View(model);
    }
     
    [HttpPost]
    public ActionResult Index(MyModel model)
    {
       if (ModelState.IsValid)
       
          // Access Violation, because model.treeData is null.  Why?
          foreach (var x in model.treeData)
          {
            if (x.Checked)
            {      
              // do something
             }
          }
        }
         
        // Have to do this or View(model) will break,
        // because there is no treeData in it.    
        model = GetPubTreeModel(model.SelectedUserId);
         
        return View(model);
    }

  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 09 Jan 2015 Link to this post

    Hello Kellie,

    Online no matter what technology you have selected the demo that you see in action is the JavaScript demo, only the code for the demo is changed.

    The button that you mentioned should actually perform a post and you should see the items that were selected in the TreeView on a DIV that is rendered from the server side. You can see the action method for the POST method and see that the selected IDs are actually retrieved on the server side after a post.

    Here is a screencast that should give you a better idea what the purpose of the demo is

    http://screencast.com/t/yzu91W5h8uEv

    Regards,
    Petur Subev
    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.

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