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
Children(Func > selector) - {
- // if (selector == null) //throw new ArgumentNullException("selector");
- _childrenProperty = selector;
- return this;
- }
my employee controller as following
- public class EmployeeController : Controller
- {
- // GET: Employee
- HRSystem hr = new HRSystem();
- public ActionResult Index()
- {
- IEnumerable
catgory1 = hr.Employees.Where(x => !x.DepartmentID.HasValue).ToList(); - return View(catgory1);
- }
- }
my error show on view of index as following
- @model IEnumerable
- @using System.Web.UI.WebControls
- @using EmployeeSystem.Models;
TreeView
- "~/Content/jsTree/themes/default/style.min.css" rel="stylesheet" />
- class="form-body">"jstree">
- @(Html.TreeView(Model)
- .EmptyContent("root")
- .Children(m=>m.EmployeeName)
- .HtmlAttributes(new { id = "tree" })
- .ChildrenHtmlAttributes(new { @class = "subItem" })
- .ItemText(m => m.EmployeeName)
- .ItemTemplate(
- @
- "@item.EmployeeName" desc="@item.EmployeeName">@item.EmployeeName
- )
- )
- 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
(); - }
- public int DepartmentID { get; set; }
- [StringLength(50)]
- public string DepartmentName { get; set; }
- public virtual ICollection
Employees { get; set; } - }
error display on line Children(m=>m.EmployeeName) on view of index
How to solve it
Replies
Know the answer? Post it — somebody with the same question will find it here.