1

Im using Contoso university tutorial and Im trying to modify it by this tutorial:

https://www.youtube.com/watch?v=B59skvlroyc

When Im done it I see this error in browser inspector (F12)

https://www.dropbox.com/s/wy1c6ocxxbke1f2/error.jpg?dl=0

Failed to load resource: the server responded with a status of 404 (Not Found)

Could somebody explain where is the problem?

Controller:

public PartialViewResult Top3()
        {
            List<Student> model = Students.OrderByDescending(s => s.Enrollments.Select(s => s.Course.Credits)).Take(3).ToList();
            return PartialView("_Student", model);
        }

Index View:

@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 }))

Partial View:

@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>
3
  • What is your route configuration?
    – DavidG
    Oct 7, 2014 at 13:20
  • routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    – Warlock
    Oct 7, 2014 at 13:40
  • Should be different?
    – Warlock
    Oct 7, 2014 at 13:43

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.