如何修复“ System.InvalidOperationException”

时间:2019-10-17 02:42:50

标签: c# sql database authentication model-view-controller

我正在尝试在ASP.Net Web应用程序上创建登录页面。但是,当我单击登录按钮时,出现了此错误:“ System.InvalidOperationException:'实体类型UserTable不是当前上下文模型的一部分。”

这是代码


        public ActionResult Authorise(UserTable user)
        {
            using (DBModels db = new DBModels())
            {
                var userDetail = db.UserTables.Where(x => x.username == user.username && x.password == user.password).FirstOrDefault();
                if(userDetail == null)
                {
                    user.LoginErrorMsg = "Invalid Username or Password";
                    return View("Index", user);
                }
                else
                {
                    Session["id"] = user.id;
                    return RedirectToAction("Index", "Home");
                }
            }

        }

1 个答案:

答案 0 :(得分:0)

远射:$.ajax({ type:'POST', dataType: JSON, url: 'http://localhost/UPLOAD-THIS/public/api/place-order', data: {"order":[{"id":2,"restaurant_id":2,"item_category_id":1,"name":"Burger","price":"10.00","image":"/assets/img/items/1570619770Fblsy6snNM.png","is_recommended":1,"is_popular":1,"is_new":1,"desc":null,"placeholder_image":"/assets/img/items/small/1570619770Fblsy6snNM-sm.png","is_active":1,"addon_categories":[],"quantity":1}, {"id":3,"restaurant_id":2,"item_category_id":1,"name":"Pizza","price":"20.00","image":"/assets/img/items/1570619787yieN7hwXCQ.jpg","is_recommended":1,"is_popular":1,"is_new":1,"desc":null,"placeholder_image":"/assets/img/items/small/1570619787yieN7hwXCQ-sm.jpg","is_active":1,"addon_categories":[],"quantity":1}], "coupon":[],"location":"Campus","order_comment":null,"total":{"productQuantity":2,"totalPrice":30},"method":"Wallet","payment_token":""}, success: function(e) { alert(success); }, error: function(e) { alert(JSON.stringify(e)); } }); 和“ UserTable”之间不匹配。

如果您有

,就会发生这种情况
UserTables

并且数据库中的表不称为[Table("UserTable")] public class UserTables