Razor TreeView - how are checked notes posted?

8 posts, 1 answers
  1. Derek
    Derek avatar
    12 posts
    Member since:
    Jan 2011

    Posted 01 Nov 2012 Link to this post

    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
  2. Answer
    Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 06 Nov 2012 Link to this post

    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!
  3. Derek
    Derek avatar
    12 posts
    Member since:
    Jan 2011

    Posted 08 Nov 2012 Link to this post

    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

  4. Eran
    Eran avatar
    4 posts
    Member since:
    Apr 2013

    Posted 08 May 2013 Link to this post

    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 ?
  5. Sean Mars
    Sean Mars avatar
    10 posts
    Member since:
    Jan 2007

    Posted 13 Aug 2013 Link to this post

    Eran, I would also like to know how that property name can be changed if I have more than one tree view. 
  6. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2527 posts

    Posted 14 Aug 2013 Link to this post

    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!
  7. Sean Mars
    Sean Mars avatar
    10 posts
    Member since:
    Jan 2007

    Posted 11 Dec 2013 Link to this post

    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. 
  8. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2527 posts

    Posted 12 Dec 2013 Link to this post

    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!
Back to Top