私にはクラスの生徒がいます:
public class Student
{
public int StudentId{get;set;}
public string StudentName{get;set;}
public int Age{get;set;}
public List<Course> Courses{get;set;}
public List<string> MobileNumbers{get;set;}
}
そして、コースクラスは次のとおりです。
public class Course
{
public int CourseId {get;set;}
public string CourseName {get;set;}
public List<Staff> Staff {get;set;}
}
スタッフクラスの構造は次のとおりです。
public class Staff
{
public int StaffId {get;set;}
public string StaffName {get;set;}
}
データをViewBagに入れましたが、foreachステートメントを使用してこれらすべてのレコードを次のビューに出力する方法がわかりません。意見:
<table class="tableStyle" width="100%" border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th>Student Name</th>
<th>Courses</th>
<th>Staffs</th>
<th>Mobile Numbers</th>
</tr>
</thead>
@foreach (Student stud in ViewBag.students)
{
<tr>
<td>@stud.StudentName</td>
foreach(Course course in ViewBag.courses)
{
<td>@course.CourseName</td>
}
foreach(Staff staff in ViewBag.staff)
{
<td>@staff.StaffName</td>
}
</tr>
}
</table>
ただし、これは、最初のforeachループにあるため、すべての学生が1人の学生のために受講したコースを印刷します。どうか、これを行う方法を教えてください... !!