首页 > 解决方案 > 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>

标签: asp.net-mvcvisual-studioweb-applicationsasp.net-mvc-5

解决方案


推荐阅读