An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code while Registering
14,499
The entity type user is not part of the model for the current context.
This is the salient part. Is the User object part of your MyDatabase2Entities context? It appears not.
Comments
-
noobie-php almost 2 years
I am getting following exception in my code.
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.
Following is my Register Controller.
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); } } }
I am totally new to ASP.net and MVC so please tell if i miss anything, i will post it here.