Hello
How to get checked nodes values.
send by form and post method but in controller cant get data
and try send by jquery
For example in the image below
How to get the value of Australia,Victoria,Acer,Brazil nodes
I tried to do it with this code but it did not work.
var instance= document.getElementById("tree").ej2_instances[0];var check=instance.getAllCheckedNodes();var i=0;var checkedNodes;while(icheckedNodes.push(instance.element.querySelector('[data-uid="' + checkedNodes[i] + '"]'));i++}console.log(checkedNodes)
Hi hkourd,
Greetings from Syncfusion support.
We have validated your requirement in Syncfusion TreeView control. We would like to let you know that TreeView control is not a form control so, we cannot get the value directly in server side. We can achieve this requirement by using the below ways.
Way : using hidden input
We can create the hidden input and we need to update the value while checking the tree nodes. On the form submit we can get the checked nodes value in server side. please refer to the below code block.
|
[Index.cshtml],
<form method="post" enctype="multipart/form-data"asp-controller="Home"asp-action="SaveData"> <input type="hidden" name="checkTree" id="checkTree"> <ejs-treeview id="treedata" showCheckBox="true" nodeChecked="onNodeChecked"> <e-treeview-fields dataSource="ViewBag.dataSource" id="id" parentId="pid" text="name" hasChildren="hasChild" expanded="expanded"></e-treeview-fields> </ejs-treeview> <input type="submit"value="save"/> </form> <script> function onNodeChecked(args){ $("#checkTree").val(this.checkedNodes); } </script> |
|
[HomeController.cs],
public IActionResult SaveData() { var value = HttpContext.Request.Form["checkTree"]; return View(); } |
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/WebApplication1-334679075.zip
We have attached the sample for your reference. Please check the attached sample and get back to us if you need any further assistance.
Regards,
Sivakumar S
Thanks for your support
In the image I sent, I want the Victoria and Australia value to be sent when Victoria is checked and sent. But in the sample you sent, only the value of Victoria is sent
Hi hkourd,
We have validated your reported issue in the ASP.NET Core TreeView component. We understand that you have to send all the auto-checked node details of the corresponding checked node to the controller. To achieve your requirement, we suggest you use the nodeChecked event arguments to get all the intermediate node details. We have modified the sample to pass the id value of all the checked nodes to the controller. Please check the attached sample for your reference.
Refer to the below code snippet.
|
[Index.cshtml]
<script> function onNodeChecked(args){ var Data=[]; for(var i=0;i<args.data.length;i++){ Data.push(args.data[i].id); } $("#checkTree").val(Data.toString()); } </script> |
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/WebApplication1-954777238.zip
Please check the attached sample and get back to us if you need any further assistance.
Regards,
Sivakumar S