asp.net“/”应用程序中的 mvc 5 服务器错误

asp.net mvc 5 Server Error in '/' Application

我现在使用 asp.net mvc 5 和 entity framework 创建示例项目 运行 这个项目我遇到了这个错误:

我的电脑安装了 .net 4.5 和 4.5.1,我的 iis 版本也是 8。

这是我的控制器:

    using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using mvcWebApp01.Models;

namespace mvcWebApp01.Controllers
{
    public class HomeControllers : Controller
    {
        private DataBaseContext db = new DataBaseContext();

        // GET: HomeControllers
        public ActionResult Index()
        {
            return View(db.People.ToList());
        }

        // GET: HomeControllers/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Person person = db.People.Find(id);
            if (person == null)
            {
                return HttpNotFound();
            }
            return View(person);
        }

        // GET: HomeControllers/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: HomeControllers/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "Id,FullName")] Person person)
        {
            if (ModelState.IsValid)
            {
                db.People.Add(person);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(person);
        }

        // GET: HomeControllers/Edit/5
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Person person = db.People.Find(id);
            if (person == null)
            {
                return HttpNotFound();
            }
            return View(person);
        }

        // POST: HomeControllers/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include = "Id,FullName")] Person person)
        {
            if (ModelState.IsValid)
            {
                db.Entry(person).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(person);
        }

        // GET: HomeControllers/Delete/5
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Person person = db.People.Find(id);
            if (person == null)
            {
                return HttpNotFound();
            }
            return View(person);
        }

        // POST: HomeControllers/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            Person person = db.People.Find(id);
            db.People.Remove(person);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}

ASP.NET 遵循 "convention over configuration" 方法。这意味着,例如,为了实例化您的控制器,默认控制器工厂将尝试按照命名约定 <Name>Controller 查找 类。如果您不喜欢这种方法,您可以编写自己的控制器工厂(参见 示例),但通常没有必要这样做。

因此,要解决您的问题,您应该将 HomeControllers 重命名为 HomeController