您需要为创建项
users
并将其添加到数据库中。
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ReferentID,FirstName,LastName,Phone,Email,Password,ConfirmPassword")] Referents referents)
{
if (ModelState.IsValid)
{
// Create the user data for the current referent.
Users currentUser = new Users(){
FirstName = referents.FirstName,
UserRole = "referent"
// .... Finish initializing fields of your model.
};
db.Referents.Add(referents);
// Save the new user in your database.
db.Users.Add(currentUser);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(referents);
}
如果没有看到模型代码,就很难具体化,但您应该能够将其作为示例。只需将currentUser对象初始化为所需的状态。根据您的模式,这可能不起作用。