We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Checking Checkboxes in TreeView

Thread ID:

Created:

Updated:

Platform:

Replies:

110580 Aug 13,2013 10:54 AM Nov 25,2013 09:47 AM ASP.NET MVC (Classic) 4
loading
Tags: Tools
Nick Howard
Asked On August 13, 2013 10:54 AM

I'm creating a tree and I need to show checkboxes. That works fine. I'm using the code below. My model structure has an id, parentid, and name. So, first I grab the record where the parentid is null and then I recursively find the child records. That all works fine. As part of my model I also have a list of ids where the checkbox needs to be checked. Can I do that in the view? Or do I need to do that in the controller? Or maybe I should ask, do I need to create the TreeView entirely in the controller?

Thanks for any help.

 @helper TreeView(IEnumerable<ItemClass> items)
                {        
                    foreach (var item in items) 
                     {
                        <li>
                            @Html.DisplayFor(i => item.Name)
        
                                <ul>
                                    @TreeView(Model.Items.Where(i=>i.ParentId==i.Id))
                                </ul>
                        </li>
                    }
                }

                <ul id="treeView" class="visibleHide">
                    @TreeView(Model.Items.Where(o=>o.ParentId == null))
                </ul>


Nick Howard
Replied On August 13, 2013 01:14 PM

I think I need to expand my question a bit. How do I access the tree view on my HttpPost? I have this:

[HttpPost]
public ActionResult Edit(ViewModel model, TreeViewModel treeViewModel)
{
    ...
}

treeViewModel is never has any items in it. I'm obviously doing something wrong, but I don't know what it could be. I didn't see any examples that showed how to figure out what's checked. Did I miss one?

Thanks for any help, I really appreciate it.

Nick


Gurunathan A [Syncfusion]
Replied On August 23, 2013 06:27 AM

Hi Nick,

Thanks for contacting Syncfusion support.

We have updated with response for the query reported in this forum in the incident 111978 which was created by you. Kindly we request you to follow that incident for further assistance.

Thanks,

Gurunathan


John Hind
Replied On November 22, 2013 06:59 AM

Hi,

I have a similar problem in that I cannot see the items that are checked after the form is submitted. Can you please tell me how to do it ?


thanks

John


John Hind
Replied On November 25, 2013 09:47 AM

Create a hidden input field on the form and then string the checked id's into it. Pick it up in your controller...

<input type="hidden" id="hidCodings" name="hidCodings" />

....       

....

...then use the following script...

var checked = $find("MyTreeView").GetAllCheckedNodes();

$("#hidCodings").val("");

$.each(checked, function (i, nodeitem) {

var nodeid = $("#hidCodings").val() != "" ? $("#hidCodings").val() + "," + $(nodeitem)[0].id : $(nodeitem)[0].id;

$("#hidCodings").val(nodeid);

});


John



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;