asp.net-mvc - ASP.net MVC Visual Studio 404 错误页面
问题描述
我是使用 Visual Studio 2017 在 mvc-5 Web 应用程序上学习的初学者。处理作业需要创建页眉中包含客户的页面,当我单击它时,将出现 2 个客户名称,每个客户名称都有不同的 ID 超链接. 每当我构建并运行项目时,就会出现 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 CustomersController : Controller
{
public ViewResult Index()
{
var customers = GetCustomers();
return View(customers);
}
public ActionResult Details(int id)
{
var customer = GetCustomers().SingleOrDefault(c => c.Id == id);
return View(customer);
}
private IEnumerable<Customers> GetCustomers()
{
return new List<Customers>
{
new Customers { Id = 1, Name = "John Smith" },
new Customers { Id = 2, Name = "Mary Williams" }
};
}
}
}
我有两个视图:客户的索引和详细信息索引:
@model IEnumerable<VIDLY.Models.Customers>
@{
ViewBag.Title = "Customers";
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", "Customer", new { id = customer.Id }, null)</td>
</tr>
}
</tbody>
</table>
}
客户详情:
@model VIDLY.Models.Customers
@{
ViewBag.Title = "Customer";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>@Model.Name</h2>
客户型号:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace VIDLY.Models
{
public class Customers
{
public int Id { get; set; }
public string Name { get; set; }
}
}
我有另一个共享视图,我将其命名为 _navbar 用于 _layout 导航栏:
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("Vidly", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Customer", "Index", "Customer")</li>
<li>@Html.ActionLink("Movies", "Index", "Movies")</li>
</ul>
</div>
</div>
</div>
解决方案
推荐阅读
- calculator - 带有 Python 的 TI 84 Plus CE 无法以度数处理复杂的极坐标形式
- json - 配置服务不允许将规则上传到 AWS Config
- arrays - 第二次后从数组中删除所有内容\n
- python - 如何以递归方式将数字总和打印到n?
- for-loop - for 循环是否遍历 Lua 和 Love2d 中的空表?
- testing - 为什么我不能在 DW 测试中测试不为零且介于 -1 和 1 之间的自相关?
- mysql - 往返中的多个航班号 - MySQL
- ios - @Published 属性内模型更新时的 SwiftUI 触发功能
- python - 之间有什么不同。和 () 在 python
- git - 在不删除文件的情况下撤消未提交的 Git 更改 - 我错误地添加了我的计算机文件,我需要将其撤消