我在 Db 中有注册模型,控制器中的以下 post 方法对数据库进行了更新。但是我也想更新登录数据模型
[HttpPost]
public ActionResult Register(StudentDetail details)
{
if (DbAccess.LoginDetails.FirstOrDefault(student => student.Username == details.Username) == null)
{
DbAccess.StudentDetails.Add(details);
**//here i also want to update login table with added details in database**
DbAccess.SaveChanges();
return RedirectToAction("HomePage");
}
return View();
}
下面是实体框架db首先创建的模型
public StudentDetail()
{
this.UserFriends = new HashSet<UserFriend>();
}
public string StudentName { get; set; }
public string UnivName { get; set; }
public string City { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string EmailId { get; set; }
public virtual ICollection<UserFriend> UserFriends { get; set; }
}
public partial class LoginDetail
{
public string Username { get; set; }
public string Password { get; set; }
}
你们能否建议我在该帖子方法中使用用户名和密码来更新 LoginDetail 表。
谢谢,
迈克尔德