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);
        }
    }
}
6
  • Change HomeControllers to HomeController Commented Jan 10, 2016 at 22:13
  • Check the event viewer, it usually has more descriptive error messages than IIS Commented Jan 10, 2016 at 22:15
  • tanks so much @miparnisari you safe my life :) Commented Jan 10, 2016 at 22:37
  • You're welcome. I wrote an answer that expands on that coment. Commented Jan 10, 2016 at 22:42
  • 2
    I have removed [solved] from your title. If you want to mark a question as solved, click the checkmark next to an answer. Do not edit the word into your title. Commented Jan 10, 2016 at 23:29

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.