Jika Anda belum memiliki model tampilan untuk mewakili ini, buat saja:
public class MyViewModel
{
public Engineer Engineer { get; set; }
public List<Element> Elements { get; set; }
}
Isi satu set model tampilan di pengontrol
public ActionResult MyAction()
{
var viewModels =
(from e in db.Engineers
select new MyViewModel
{
Engineer = e,
Elements = e.Elements,
})
.ToList();
return View(viewModels);
}
Dan dalam tampilan Anda, tentukan saja bahwa Anda menggunakan kumpulan model tampilan:
@model List<MyViewModel>
@foreach(var vm in Model)
{
<h1>Projects for engineer: @vm.Engineer.Name</ha>
<ul>
@foreach(var ele in vm.Elements)
{
<li>@ele.Name</li>
}
</ul>
}