微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

编辑操作不会在带有会话参数的数据库 ASP.NET MVC 中更新

如何解决编辑操作不会在带有会话参数的数据库 ASP.NET MVC 中更新

我想从用户登录数据库中编辑用户详细信息,登录后我进行会话:

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(Login login,string ReturnUrl = "")
{
        .....
        if (v != null)
        {
            if ((bool)!v.IsEmailVerified)
            {
               ........
            }

            if (string.Compare(Crypto.Hash(login.password),v.password) == 0)
            {
               ....
               Session["EmailID"] = v.email;
            }
       }
}

对于登录和编辑操作,它们有不同的控制器,登录userController 中,而编辑操作在 userdashController 中,其中编辑操作:

db_userEntities1 db = new db_userEntities1()

public ActionResult EditProfile(string EmailId)
{
    EmailId = Session["EmailID"].ToString();

    var edit = db.tbl_user.Where(i => i.email == EmailId).FirstOrDefault();

    return View(edit);
}

// POST: Customer/Edit/5
[HttpPost]
public ActionResult EditProfile(string EmailId,tbl_user user)
{
    using (db_userEntities1 dc = new db_userEntities1())
    {
        // Todo: Add update logic here

        var userdata = dc.tbl_user.Where(s => s.email == user.email).FirstOrDefault();
        dc.Entry(userdata).State = System.Data.Entity.EntityState.Modified;
        dc.SaveChanges();

        return RedirectToAction("Index","Home");
    }
}

当我保存它时,它会直接进入索引,但数据库尚未更新。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。