An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code while Registering

asp.net asp.net-mvc asp.net-mvc-5 c# entity-framework

Question

In my code, I am experiencing the following exception.

An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code.

Additional information: The entity type user is not part of the model for the current context.

My register controller is listed below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Registration2.Controllers
{
    public class userController : Controller
    {
        // GET: user
        public ActionResult Index() => View();
        public ActionResult Register() => View();

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Register(Registration2.user U)
        {
            if (ModelState.IsValid)
            {
                using (MyDatabase2Entities dc = new MyDatabase2Entities())
                {
                    //you should check duplicate registration here 
                    // dc.users.Add

                    dc.users.Add(U);
                    dc.SaveChanges();
                    ModelState.Clear();
                    U = null;
                    ViewBag.Message = "Successfully Registration Done";
                }
            }
            return View(U);
        }
    }
}

Please let me know if I'm missing anything because I'm completely new to ASP.net and MVC. I'll post it below.

1
3
1/2/2016 9:14:32 AM

Accepted Answer

ZZZ_tmp
4
5/22/2015 3:20:59 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow