我在MVC项目中遇到了一些问题。一切正常,但客户控制器无法正常工作。它之前做得很好,但现在它产生了这个错误
' /'中的服务器错误应用
无法找到资源。
描述:HTTP 404.您正在查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下网址,确保拼写正确。
以下是客户控制器的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Vidly.Models;
namespace Vidly.Controllers
{
public class CustomerController : Controller
{
// GET: Customer
public ViewResult Index()
{
var customers = GetCustomers();
return View(customers);
}
public ActionResult Details(int id)
{
var customer = GetCustomers().SingleOrDefault(c => c.id == id);
if (customer == null)
{
return HttpNotFound();
}
return View(customer);
}
private IEnumerable<Customer> GetCustomers()
{
return new List<Customer>
{
new Customer {id = 1, Name = "John Smith" },
new Customer {id = 2, Name = "Mary Williams" }
};
}
}
}
客户视图中的索引操作代码
@model IEnumerable<Vidly.Models.Customer>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Customers</h2>
@if (!Model.Any())
{
<p>We don't have any customers yet.</p>
}
else
{
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Customer</th>
</tr>
</thead>
<tbody>
@foreach (var customer in Model)
{
<tr>
<td>@Html.ActionLink(customer.Name, "Details", "Customers", new { id = customer.id }, null)</td>
</tr>
}
</tbody>
</table>
}
客户的详细信息操作视图实施
@model Vidly.Models.Customer
@{
ViewBag.Title = "Details";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>@Model.Name</h2>