【发布时间】:2013-02-19 20:53:47
【问题描述】:
我试图将 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.List1[<>f__AnonymousType72[f__AnonymousType63[System.Int32,System.Int32,System.Int32],System.Int32]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[System.Linq.IGrouping`2[System.Object,FYPSchoolApp.DAL。 ClassInstanceDetail]]'。
【问题讨论】:
标签: asp.net-mvc linq razor