我想在用户注册后将数据保存到我的数据库中。我在 Account 控制器的 Registerfunctin 中编写了代码。代码是:
[HttpPost]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus;
Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
///My code for saving in dtabase
Recommend ad = new Recommend();
ad.estate = 1;
ad.industry = 1;
storedb.AddToRecommends(ad);
storedb.SaveChanges();
///
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", ErrorCodeToString(createStatus));
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
推荐的是我想在房地产和行业列中存储 1 的表的名称。我用这种方式在另一个控制器中保存之前,一切都很好,但现在我得到了这个异常:
谁能告诉我有什么问题?非常感谢