简体   繁体   English

更新到实体框架6后,我的ajax调用不起作用

[英]After updating to entity framework 6 my ajax call is not working

I am making a wedding website. 我正在制作一个婚礼网站。 After realizing I needed to update to entity framework 6 my Controller stopped working. 意识到之后,我需要更新到实体框架6,我的控制器停止工作。 I am using ajax call to see if user has allready logged in and then he doesn't need to log in each time he/she has been away. 我正在使用ajax调用来查看用户是否已经全部登录,然后他/她每次离开时都不需要登录。

I get blablabla.Table does not contain a defintion for "LoggedIn" 我得到blablabla.Table没有包含“ LoggedIn”的定义

This worked before I updated to entityframework 6..... why doesn't it work now? 在我更新到entityframework 6 ......之前,此方法起作用了,为什么它现在不起作用?

This is my code 这是我的代码

Controller: 控制器:

        public ActionResult Login(Table u)
        {
            // this action is for handle post (login)
            if (ModelState.IsValid) // this is check validity
            {
                using (LoginEntities dc = new LoginEntities())
                {
                    var v = dc.Tables.Where(a => a.Username.Equals(u.Username) && a.PassWord.Equals(u.PassWord)).FirstOrDefault();
                    if (v != null)
                    {
                        FormsAuthentication.SetAuthCookie(u.Username, true);
                        u.LoggedIn = true;
                        return Json(u);
                    }
                    else
                    {

                        u.LoggedIn = false;
                        u.Message = "You have entered the wrong password, please try again!";
                        return Json(u);



                    }
                }
            }
            return View(u);
        }
    }

}

Script: 脚本:

$("#LoginForm").submit(function (event) {

    event.preventDefault();
    var url = $(event.target).attr("action");
    //var username = $("#Username");
    var model = $(event.target).serialize();
    //console.log(model);
    console.log(url);
    $.ajax({

        url: url,
        data: model,
        type:"POST",
        success: function (response) {
            console.log("bla");
            if (response.LoggedIn) { window.location = "/Home/Index" } else
            { alert(response.Message); }
        }

    });

});

Class: 类:

    public partial class Table
    {
        public int UserID { get; set; }
        public string Username { get; set; }
        public string PassWord { get; set; }
    }
}

In your code you have this line: 在您的代码中,您具有以下这一行:

u.LoggedIn = true;

The variable u is of type Table that has no property called LoggedIn . 变量uTable类型的,没有名为LoggedIn属性。 The error is nothing to do with entity framework. 该错误与实体框架无关。

Table is a partial class though so may have been extended somewhere else previously. 尽管Table是局部类,所以以前可能已经在其他地方进行了扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM