我试图将 linq 列表对象从我的控制器传递到我的视图。linq 对象包含一个引发某种错误的分组。我只想在视图中显示分组的对象。linq 语句完美运行,但显示语句却不行!任何帮助将不胜感激!
控制器
public ViewResult StudentAttendanceForYear(int id)
{
DateTime finDate = System.DateTime.Today;
DateTime strtDate = DateTime.Today.AddMonths(-6);
var chosenStudent = (from t in db.ClassInstanceDetails.Include("Student")
where (t.Attendance == false) && (t.StudentID == id)
&& (t.ClassInstance.Date > strtDate) && (t.ClassInstance.Date < finDate)
group t by new { t.ClassInstance.Date.Year, t.ClassInstance.Date.Month, t.ClassInstance.Date.Day } into grp
select new
{
absentDate = grp.Key,
numAbsences = grp.Count(t => t.Attendance == false)
}).ToList();
return View(chosenStudent.ToList());
}
看法
我试着改变我的看法
@model IEnumerable<System.Linq.IGrouping<object, FYPSchoolApp.DAL.ClassInstanceDetail>>
但仍然没有运气,我不断收到以下错误:
传入字典的模型项的类型为“System.Collections.Generic.List 1[<>f__AnonymousType7
2[<>f__AnonymousType6 3[System.Int32,System.Int32,System.Int32],System.Int32]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1[System.Linq.IGrouping`2[System.Object,FYPSchoolApp.DAL.ClassInstanceDetail]]”。