I need to convert static query of complex model binding to the dynamic LINQ query in controller action to get data from database through EF
This is my Model
- public class DepartmentViewModel
- {
- public int DepartmentId { get; set; }
- public string Name {get; set;}
- public List stdList { get; set; }
-
- public DepartmentViewModel()
- {
- stdList = new List();
- }
- }
-
- public class StdListModel
- {
- public int ID { get; set; }
- public string Name { get; set; }
- }
and controller is as:
- public ActionResult Index()
- {
- List list = new List();
- DepartmentViewModel dept = new DepartmentViewModel();
-
- dept.DepartmentId = 1;
- dept.Name = "Department 1";
- dept.stdList.Add(new StdListModel() { ID = 1, Name = "Some Name" });
- dept.stdList.Add(new StdListModel() { ID = 2, Name = "Another Name" });
- list.Add(dept);
-
- return View(list);
- }
i need to change this controller action static list to dynamic linq query to get data from database EF and bind to Model.