我正在使用Contoso大学教程,我试图通过本教程修改它:
https://www.youtube.com/watch?v=B59skvlroyc
当我完成它时,我在浏览器检查器(F12)中看到此错误
https://www.dropbox.com/s/wy1c6ocxxbke1f2/error.jpg?dl=0
无法加载资源:服务器响应状态为404(未找到)
有人可以解释问题出在哪里吗?
控制器:
public PartialViewResult Top3()
{
List<Student> model = Students.OrderByDescending(s => s.Enrollments.Select(s => s.Course.Credits)).Take(3).ToList();
return PartialView("_Student", model);
}
索引视图:
@model PagedList.IPagedList<ContosoUniversity.Models.Student>
@using PagedList.Mvc;
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />
<script src="../Scripts/jquery-1.8.0.min.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
@{
ViewBag.Title = "Students";
}
<h2>Students</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
@using (Html.BeginForm("Index", "Student", FormMethod.Get))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<p>
Find by name: @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
Enrollment:
<input type="submit" value="Filter" />
</p>
}
<table class="table">
<tr>
<th>
@Html.ActionLink("Last Name", "Index", new { sortOrder = ViewBag.NameSortParm })
</th>
<th>
First Name
</th>
<th>
@Html.ActionLink("Enrollment Date", "Index", new { sortOrder = ViewBag.DateSortParm })
</th>
<th>
Date Of Birth
</th>
<th>
Courses
</th>
<th>
Credits
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.FirstMidName)
</td>
<td>
@Html.DisplayFor(modelItem => item.EnrollmentDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateOfBirth)
</td>
<td>
@string.Join(",", item.Enrollments.Select(e => e.Course.Title))
</td>
<td>
@item.Enrollments.Sum(e => e.Course.Credits)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
</tr>
}
</table>
<br />
@Ajax.ActionLink("Top3", "Top3", new AjaxOptions()
{
HttpMethod = "GET",
UpdateTargetId = "divStudents",
InsertionMode = InsertionMode.Replace
})
<span style="color:Blue"></span>
<div id="divStudents">
</div>
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Index",
new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))
部分视图:
@model IEnumerable<ContosoUniversity.Models.Student>
<h3>Top 3 Student</h3>
<table style="border: 1px solid black; background-color:silver">
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.FirstMidName)
</td>
<td>
@Html.DisplayFor(modelItem => item.EnrollmentDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateOfBirth)
</td>
<td>
@string.Join(",", item.Enrollments.Select(e => e.Course.Title))
</td>
<td>
@item.Enrollments.Sum(e => e.Course.Credits)
</td>
</tr>
}
</table>