【发布时间】:2018-07-19 09:10:05
【问题描述】:
我因按月显示学生出勤视图而陷入困境。我正在尝试使用 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>
}
我只想知道如何将数据从控制器传递到视图,以及是否需要在视图中进行任何更改。
任何帮助将不胜感激。感谢你。
【问题讨论】:
-
明智地获取数据 Student 并不是很复杂,尽管很大程度上取决于您获取数据的方式。您当然可以按学生分组,然后分组值应包含
List,其中包含每天和出勤数据。有关如何存储数据的更多信息会有所帮助。现在你如何展示它是你的选择,与 Linq 无关 -
谢谢@MrinalKamboj.. 但是我将如何在标题行下显示缺席的日子?
-
我的意思是 jquery 函数将传递天数,然后我将使用 for 循环遍历该数字。并将其显示到标题。我将如何在确切日期(数字)下方显示我的状态@MrinalKamboj
-
您在错误的类别下发布了您的问题,一旦您将数据作为包含日期和出勤信息的列表,使用
GroupBy很简单,那么更多关于JQuery将如何处理它用正确的标签和相关信息发布问题 -
如果我不使用 jquery @MrinalKamboj.. 有什么其他方法可以使用 linq 实现它吗?
标签: asp.net-mvc linq linq-to-sql