我需要按班级和科目显示学生的数据,已完成所有操作,但我仍想按照控制器上的班级和科目显示针对其费用类型ID的清单费用,然后按学生ID显示。 >
Class:VIII Section:Blue
|StudentName|Class|Section|GrandTotal|Admission Fee|TutionFee|TransportFee|
|Ali |VIII |Blue | 20$ | 5$ | 11$ | 4$ |
|Jastin |VIII |Blue | 20$ | 5$ | 11$ | 4$ |
|Kim |VIII |Blue | 20$ | 5$ | 11$ | 4$ |
`public JsonResult StudentSearch(int? classId,int?sectionId)
{
var listOfIds = _dbContext.STUDENT_FEE_DETAIL
.Where(n=>n.STUDENT_FEE_ID ==n.StudentFee.STUDENT_FEE_ID)
.Select(n=>n.AMOUNT);
var fee = _dbContext.STUDENT_FEE.ToList().Where(c=>c.IsActive);
var sec = _dbContext.SECTION.ToList();
List<StudentInfoViewModel> SiVM =new List<StudentInfoViewModel>();
if (classId >0 && sectionId>0)
{
var students = _dbContext.STUDENTINFO.Include(i =>i.Class).
ThenInclude(c => c.Section).Where(c=>c.ClassId== classId
&& c.SectionId == sectionId);
foreach (var item in students)
{
SiVM.Add(new StudentInfoViewModel
{ Id = item.Id,
AdmissionNumber = item.AdmissionNumber,
FullName = item.FullName,
ClassName = item.Class.ClassName,
SectionName = sec.Where(c => c.Id == sectionId)
.Select(c => c.SectionName).FirstOrDefault(),
AmountDue = fee.Where(c => c.STUDENT_INFO_ID ==
item.Id && c.STUDENT_INFO.IsActive)
.Select(e =>e.GRAND_TOTAL).FirstOrDefault(),
StdFeeTypeDetail =listOfIds.ToString().FirstOrDefault(),
});
}
}
else
{
return Json(false);
}
return Json(SiVM);
}`
StdFeeTypeDetail
是float
中的StudentInfoViewModel
。
请帮助我,我是Asp.net核心中的新人
答案 0 :(得分:0)
我在listOfIds
var listOfIds = _dbContext.STUDENT_FEE_DETAIL
.Where(n=>n.STUDENT_FEE_ID==n.StudentFee.STUDENT_FEE_ID)
.Select(n=> new {
feeid = n.FEE_TYPE_ID,
feetypeName= n.FEE_TYPE.Name,
amount= n.AMOUNT,
studentid= n.StudentFee.STUDENT_INFO_ID,
studentName=n.StudentFee.STUDENT_INFO.FullName
}).GroupBy(x => x.studentid).ToList();
不能将类型System.Linq.IGrouping(int,float?)隐式转换为'float'