- Home
- Forum
- ASP.NET Core - EJ 2
- DropdownTree with "EJS-for" tag its Not Work
DropdownTree with "EJS-for" tag its Not Work
Hello! the support team
My New Project on Visual Studio 2019 and its ASP.NET CORE i have use The Control "DropdownTree" and its work fine
but when i use edit page for Employee i used "EJS-for" to mapping wicth Deparmtnet he is,
i got this error and the DropdownTree is freezed
=======================
Uncaught TypeError: Cannot read properties of undefined (reading 'toString')
at t.setValidValue (ej2.min.js:1)
at t.setTreeValue (ej2.min.js:1)
at t.render (ej2.min.js:1)
at t.appendTo (ej2.min.js:1)
at 12:1903
=======================
if i removed "EJS-for" tag the DropdownTree is fill with all Departments
html code :
@model Attendance.Models.ViewModel.EmployeeVM
@using Syncfusion.EJ2
<ejs-dropdowntree id="tree" placeholder="أختر القسم" ejs-for="Employee.DepartmentId" enableRtl>
<e-dropdowntree-fields dataSource="ViewBag.dataSource" value="DepartmentId" parentValue="ParentId" text="DepartmentName" hasChildren="hasChild" expanded="expanded"></e-dropdowntree-fields>
</ejs-dropdowntree>
<span asp-validation-for="Employee.DepartmentId" class="text-danger"></span>
And
I have checked that there is a value in "Employee.DepartmentId"
- Does this issue occur when placing the Dropdown Tree inside any other component?
- Video demonstration of the mentioned issue.
- If possible, kindly modify the above sample to reproduce the issue.
- Package version used in your application.
Hi Sharon Sanchez S.
Thank You for replay
i Run and see the sample
I guess I didn't explain or specify the problem exactly
but If you can modify the example
That there is "Department Id" for specific employee
. This means that if all the departments in the list are fill , a specific department will be identified and selected Thank you
In short, when i disply employee details, including the name of the department in which he is, and when you click on the name of the department, get a all departments comes up in case you want to transfer the employee to another department
Based on your query and error details, we suspect that you have set the ejs-for value as integer datatype, which is the cause of the issue. To overcome the reported issue, we suggest you to bind the value in string datatype as demonstrated in the below code snippet.
|
public ActionResult Index(SampleModel model)
{
ViewBag.data = new SampleModel().TreeViewdata();
model.DepartmentId = model.DepartmentId;
return View(model);
}
}
public class SampleModel
{
public String DepartmentId { get; set; }
public List<SampleModel> TreeViewdata()
{
List<SampleModel> treedata = new List<SampleModel>();
treedata.Add(new SampleModel
{
DepartmentId = "1",
DepartmentName = "Discover Music",
hasChild = true,
expanded = true
});
treedata.Add(new SampleModel
{
DepartmentId = "2",
ParentId = "1",
DepartmentName = "Hot Singles",
});
. . .
return treedata;
}
}
} |
Please find the below sample for your reference.
Please get back to us if you need further assistance.
Regards,
Hi Shalini Maragathavel
Thank you for your example
What is you mentioned the reason for the error is because the field type was a integer and this is Logical because it is the serial number of the Departments
its means the "ejs-for" tag does not work with integer value
according to your example I defined a new variable"String" in Model and used it with "ejs-for" tag , and its worked The employee Department is selected in the DropDownTree,
but there was another aproblem if you notice the example you sent. you set a value for Department Id "21" by name "Redeem a Gift Card", but when run the example the Department select is Department Id "2" by name "Hot Singles"
it will take the first number of Department id , and if there no Department number that starts with the first digit, no Department will be selected
I hope there is a solution for that , thank you
Regards
Fahad
I temporarily solved the problem by doing the following
On GET - EDIT
Controller :
ViewBag.DepartmentId = employeeVM.Employee.DepartmentId;
View :
<ejs-dropdowntree id="DepartmentTree" Created="created" ejs-for="@Model.NewDepartmentId" enableRtl>
<e-dropdowntree-fields dataSource="ViewBag.dataSource" value="DepartmentId" parentValue="ParentId" text="DepartmentName" hasChildren="hasChild"></e-dropdowntree-fields>
</ejs-dropdowntree>
<span asp-validation-for="@Model.NewDepartmentId" class="text-danger"></span>
<script type="text/javascript">
function created(args) {
var treeObj = document.getElementById("DepartmentTree").ej2_instances[0];
var DepartmentId= @ViewBag.DepartmentId;
treeObj.value = [Parent.toString()];
}
</script>
On POST - EDIT
Controller :
obj.Employee.DepartmentId = int.Parse(obj.NewDepartmentId);
We have validated your query. The value bound to the ejs-for should be in string array type, so you can resolve this issue by binding the ejs-for value in string array datatype as demonstrated in the below code snippet,
|
<ejs-dropdowntree id="tree" placeholder="أختر القسم" ejs-for="@Model.DepartmentId1" enableRtl>
. . .
</ejs-dropdowntree>
---------------------------------------------------------------------- public IActionResult Index() {
ViewBag.data = new SampleModel().TreeViewdata();
model.DepartmentId1 = new String[] {"21"};
return View(model);
}
public class SampleModel
{
public String[] DepartmentId1 { get; set; }
} |
Please find the below sample for your reference.
If the issue persists, please share the controller code snippet of your application to validate further. So that we can check from our end and provide the prompt solution.
Regards,
Hi Shalini Maragathavel
Thank you for your example
The problem I was facing is solved
- 10 Replies
- 4 Participants
- Marked answer
-
FA Fahad Alsaif
- Sep 12, 2021 07:59 PM UTC
- Sep 17, 2021 05:32 AM UTC