如何在ViewModel中填充列表集合
控制器:
SchoolEntities db = new SchoolEntities();
public ActionResult Index()
{
var student= from s in db.Students
select s.Name.ToList();
return View();
}
模型视图:
public List<Student>students { get; set;}
答案 0 :(得分:0)
您需要以学生的身份返回视图,以便在您的观看中使用
public ActionResult Index()
{
var student= from s in db.Students
select s.Name.ToList();
return View(student);
}
答案 1 :(得分:0)
您可以创建ModelView
,填充它并将其传递给视图,如下所示:
public ActionResult Index()
{
var studentList = db.Students.ToList();
return View(new ModelView { students = studentList });
}