Problem
error cannot simplicity convert string to system.collection.generic.ienumerable on view of index
Details
I need to display every department and his employees following to it in tree view using jtree i downloaded from nugget in mvc 5 visual studio 2015 . as department parent and children employee
Sales(parent)
michel(children)
divid(children)
my database data as following
- SELECT dbo.Departments.DepartmentName, dbo.Employee.EmployeeName, dbo.Employee.DepartmentID
- FROM dbo.Employee INNER JOIN
- dbo.Departments ON dbo.Employee.DepartmentID = dbo.Departments.DepartmentID
and treeviewhelper class has following function for children
- public TreeView<T> Children(Func<T, IEnumerable<T>> selector)
- {
-
- _childrenProperty = selector;
- return this;
- }
my employee controller as following
- public class EmployeeController : Controller
- {
-
- HRSystem hr = new HRSystem();
- public ActionResult Index()
- {
- IEnumerable<Employee> catgory1 = hr.Employees.Where(x => !x.DepartmentID.HasValue).ToList();
- return View(catgory1);
- }
- }
my error show on view of index as following
- @model IEnumerable<EmployeeSystem.Employee>
- @using System.Web.UI.WebControls
- @using EmployeeSystem.Models;
-
- <h2>TreeView</h2>
- <link href="~/Content/jsTree/themes/default/style.min.css" rel="stylesheet" />
- <div class="form-body">
- <div id="jstree">
- @(Html.TreeView(Model)
- .EmptyContent("root")
- .Children(m=>m.EmployeeName)
- .HtmlAttributes(new { id = "tree" })
- .ChildrenHtmlAttributes(new { @class = "subItem" })
- .ItemText(m => m.EmployeeName)
- .ItemTemplate(
- @<text>
- <a href="@item.EmployeeName" desc="@item.EmployeeName">@item.EmployeeName</a>
- </text>)
- )
- </div>
- </div>
- public partial class Employee
- {
-
- [Key]
- public int EmployeeNo { get; set; }
- [StringLength(100)]
- public string EmployeeName { get; set; }
- public int? DepartmentID { get; set; }
- public virtual Department Department { get; set; }
-
- }
Department model
- public partial class Department
- {
-
- public Department()
- {
- Employees = new HashSet<Employee>();
- }
-
- public int DepartmentID { get; set; }
-
- [StringLength(50)]
- public string DepartmentName { get; set; }
- public virtual ICollection<Employee> Employees { get; set; }
- }
error display on line Children(m=>m.EmployeeName) on view of index
How to solve it