Asp.net mvc 4 在学分栏中,显示学生报名参加的所有课程的学分数量

Asp.net mvc 4 在学分栏中,显示学生报名参加的所有课程的学分数量,asp.net-mvc-4,Asp.net Mvc 4,如何在学分栏中显示学生参加的所有课程的学分数量 我需要修改Contoso大学的应用程序 视图: @model PagedList.IPagedList @使用PagedList.Mvc; 学生 @ActionLink(“新建”、“创建”) @使用(Html.BeginForm(“Index”、“Student”、FormMethod.Get)) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) 按名称查找:@Html.Text

如何在学分栏中显示学生参加的所有课程的学分数量

我需要修改Contoso大学的应用程序

视图:

@model PagedList.IPagedList
@使用PagedList.Mvc;
学生

@ActionLink(“新建”、“创建”)

@使用(Html.BeginForm(“Index”、“Student”、FormMethod.Get)) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) 按名称查找:@Html.TextBox(“SearchString”,ViewBag.CurrentFilter为字符串)

} @ActionLink(“姓氏”,“索引”,新的{sortOrder=ViewBag.NameSortParm}) 名字 @ActionLink(“注册日期”,“索引”,new{sortOrder=ViewBag.DateSortParm}) 出生日期 课程 信用 @foreach(模型中的var项目){ @DisplayFor(modelItem=>item.LastName) @DisplayFor(modelItem=>item.FirstMidName) @DisplayFor(modelItem=>item.EnrollmentDate) @DisplayFor(modelItem=>item.DateOfBirth) @string.Join(“,”,item.registrations.Select(e=>e.Course.Title)) @ActionLink(“编辑”,“编辑”,新的{id=item.id})| @ActionLink(“详细信息”,“详细信息”,新的{id=item.id})| @ActionLink(“删除”,“删除”,新的{id=item.id}) }
@Model.PageCount的@页(Model.PageCountUrl.Action(“索引”), 新建{page,sortOrder=ViewBag.CurrentSort,currentFilter=ViewBag.currentFilter})
请帮忙

我不知道怎么做


如果有人需要更多详细信息,请告诉我。

我没有Contoso大学的任何经验,但在我看来,您可以通过这样做来计算学分:

item.Enrollments.Sum(e => e.Course.Credits);

这是未经测试的,在不知道数据结构的情况下,很难确定这是否有效,但我确信查看该方法将帮助您解决问题。

@item.registrations.Sum(e=>e.Course.Credits)

“ContosoUniversity.Models.Student”不包含“Sum”的定义,并且找不到接受“ContosoUniversity.Models.Student”类型的第一个参数的扩展方法“Sum”(是否缺少using指令或程序集引用?),当然没有!)更新了我的代码,使其不会出错。
item.Enrollments.Sum(e => e.Course.Credits);