I want to save data to my database after a user registered. I wrote code in Registerfunctin in Account controller. the code is:
[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);
}
Recommend is the name of table that I want to store 1 in estate and industry column. I used this way for saving befor in another controller and everything were OK, But now I get this exception:
Can anybody tells me whats the problem? Thanks alot