我因按月显示学生出勤视图而陷入困境。我正在尝试使用 linq 实现它。我想要的输出类似于
student ID | 1 |2 |3 |4 |5 |6 |7 |8 |9 |10 |................
1 | P |P |A |L |P |A |P |L |P |A |................
我有两张桌子
学生桌
public class StudentMeta
{
public int Student_ID { get; set; }
public string Roll_No { get; set; }
public string Name { get; set; }
etc ......
}
和学生考勤表
public partial class tbl_Students_Attandance
{
public int monthdays { get; set; }
}
public class StuAttandance
{
public int id { get; set; }
public System.DateTime AttandanceDate { get; set; }
public int StudentID { get; set; }
public string Status { get; set; }
public int ClassSectionId { get; set; }
}
我将使用一个函数,在该函数中,我将通过使用 Jquery 从下拉列表中选择月份来传递月份
public ActionResult ViewMonthlyAttandance(int monthDays, int classID)
{
ViewBag.ClassesList = new SelectList(db.tbl_Classes, "Id", "Class_Name");
List<tbl_Students_Attandance> Stu_Attendence = db.tbl_Students_Attandance.Where(x => x.ClassSectionId == classID).ToList();
// here some "Group by" statment will be used to get my "P" or "A" Stu_Staus from db according to student_ID
return View();
}
我知道我的视图会是这样的
<table>
<thead>
<tr>
<th>Attendance Day</th>
@foreach (var MD in Model.MonthDays)
{
<th>@MD</th>
}
</tr>
<thead>
<tbody>
@foreach (var student in Model.Students)
{
<tr>
<td>@student.Name</td>
@foreach (var item in Model.Stu_Staus)
{
<td>@item</td>
}
</tr>
}
</tbody>
}
我只想知道如何将数据从控制器传递到视图,以及是否需要在视图中进行任何更改。
任何帮助,将不胜感激。感谢你。