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

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.

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

Accepted Answer

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.

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