0

i create sample project with asp.net mvc 5 and entity framework now when i want to run this project i encounter whit this error :

enter image description here

in my computer is installed .net 4.5 and 4.5.1 and my iis version is 8 too.

this my controller :

    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);
        }
    }
}
mason
  • 31,774
  • 10
  • 77
  • 121
saman
  • 305
  • 2
  • 4
  • 17

1 Answers1

1

ASP.NET follows a "convention over configuration" approach. This means that, for instance, in order to instantiate your controllers, the default controller factory will try to look for classes following the naming convention <Name>Controller. If you don't like this approach you can write your own Controller Factory (see here for example), but in general this is not necessary.

So to fix your problem you should rename HomeControllers to HomeController.

Community
  • 1
  • 1
Maria Ines Parnisari
  • 16,584
  • 9
  • 85
  • 130