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

TreeView Checkbox problems

1 Answer 197 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
K
Top achievements
Rank 1
K asked on 08 Jan 2015, 12:17 AM
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);
}

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 09 Jan 2015, 04:49 PM

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.

 
Tags
TreeView
Asked by
K
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or