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; }
- }
- 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);
- }

Sai Kumar KoonaRank #334 · 7.5K reputationPosted Nov 9, 2019, 10:38 PM EST
ribha shakoor62 reputationPosted Nov 10, 2019, 4:49 AM EST
Priyanka K SRank #1,385 · 1.2K reputationPosted Dec 25, 2019, 8:18 PM EST