ceci bela

ceci bela

  • NA
  • 58
  • 12.7k

Multiple Models in Single View in MVC

Aug 8 2014 3:11 PM
Hello, I am trying to replicated this http://www.c-sharpcorner.com/UploadFile/ff2f08/multiple-models-in-single-view-in-mvc/Default.aspx for my project but I am unable to load the data from database. 
 
In that example it gets all the faculty and students this way
private List<Teacher> GetTeachers()
{
List<Teacher> teachers = new List<Teacher>();
teachers.Add(new Teacher { TeacherId = 1, Code = "TT", Name = "Tejas Trivedi" });
teachers.Add(new Teacher { TeacherId = 2, Code = "JT", Name = "Jignesh Trivedi" });
teachers.Add(new Teacher { TeacherId = 3, Code = "RT", Name = "Rakesh Trivedi" });
return teachers;
}
 
Assuming that I also have public class Teacher / Student class How could I load the values from the database?   
 private List<Teacher> GetTeachers()
{
DBContextEntities db = new DBContextEntities();
List<Teacher> teachers = new List<Teacher>();
????
return teachers;
}

Answers (6)