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

Razor TreeView - how are checked notes posted?

7 Answers 126 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Derek
Top achievements
Rank 1
Derek asked on 01 Nov 2012, 05:09 PM
Hi,

Edit: the subject of this thread should contain "nodes" not "notes".

I wasn't able to find documentation on how checked nodes from a Kendo TreeView (MVC Razor) are posted to the server.  With your ASP.NET MVC extensions, I used a method on my controller of the form:

[AcceptVerbs(HttpVerbs.Post)]
 public ActionResult Update(FormCollection formCollection, List<TreeViewItem> treeView_checkedNodes)

When I use this approach with Kendo, the method is invoked but the treeView_checkedNodes argument is null.

If this is the right approach, then I can post more code so that you might help me find the problem.  But otherwise please advise as to how to obtain, from an MVC controller on the server, the TreeView's checked items.

thanks,
Derek

7 Answers, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 06 Nov 2012, 03:49 PM
Hello Derek,

The default name under which the checked items are send is checkedNodes and only the Id is sent ( not the whole TreeViewItem) so you need an array of string/int called checkedNodes.

i.e.
public ActionResult Checkboxes(string[] checkedNodes)
 
or
 
 
public ActionResult Checkboxes(int[] checkedNodes)


Kind Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Derek
Top achievements
Rank 1
answered on 08 Nov 2012, 05:43 PM
Thanks Petur - that works.

For those who are interested, a few points:
  • The name of the argument to the action method must be checkedNodes.
  • The items in the checkedNodes array are the id's (see TreeViewItem.Id) of the checked nodes, so it's important to assign the Id property of each item (and do so in a way that the checked nodes can be parsed/interpreted in the action method).
  • The action method can include an argument of type FormCollection as well.
  • I'm not sure the circumstances under which the argument could be type int[], as I thought the array was derived from the TreeViewItem.Id property (which is a string), but perhaps Petur or others can clarify.

Sincerely,
Derek

0
Eran
Top achievements
Rank 1
answered on 08 May 2013, 11:34 AM
What if i want to use several Tree views in one post? how can do I post back to mvc controller? can I set the parameter name ?
0
Sean Mars
Top achievements
Rank 1
answered on 13 Aug 2013, 07:15 PM
Eran, I would also like to know how that property name can be changed if I have more than one tree view. 
0
Alex Gyoshev
Telerik team
answered on 14 Aug 2013, 07:02 AM
Starting with the latest internal build, you can set the parameter name through the Name method of the Checkboxes fluent API:

.Checkboxes(cb => cb.Name("foo"))

Previous builds required setting a custom checkbox template in order to change the name. 

Regards,
Alex Gyoshev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Sean Mars
Top achievements
Rank 1
answered on 11 Dec 2013, 10:32 PM
Alex, can you verify, but the "change" event for TreeView now does not get fired for checkboxes assigned a Name property. Where  before the TreeView "change" event fire once I clicked in a checkbox. 
0
Alex Gyoshev
Telerik team
answered on 12 Dec 2013, 11:19 AM
Hello Sean,

The TreeView change event does not relate to the checkboxes -- it is only fired when the selected node has changed (i.e. the node is highlighted). If you need to listen to the checkbox change events, you can do so through the following jQuery:

    $("#treeview").on("change", ":checkbox", function(e) { /* code here */ });

Regards,
Alex Gyoshev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
TreeView
Asked by
Derek
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Derek
Top achievements
Rank 1
Eran
Top achievements
Rank 1
Sean Mars
Top achievements
Rank 1
Alex Gyoshev
Telerik team
Share this question
or