![](/img/trans.png)
[英]asp.net MVC 4 web application Server Error in '/' Application?
[英]asp.net mvc 5 Server Error in '/' Application
我现在想用asp.net mvc 5和实体框架创建示例项目时,当我想运行该项目时,遇到以下错误:
在我的计算机上安装了.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遵循“约定之上的配置”方法。 这意味着,例如,为了实例化您的控制器,默认的控制器工厂将尝试遵循命名约定<Name>Controller
。 如果您不喜欢这种方法,则可以编写自己的Controller Factory(例如,请参见此处 ),但是一般来说这不是必需的。
因此,要解决您的问题,您应该将HomeControllers
重命名为HomeController
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.