public ActionResult Register(RegisterViewModel users, EFUserRepository ef) { ViewBag.Region = new SelectList(repository.Regions, "RegionId", "Name"); if (ModelState.IsValid) { users.User.UserName.Trim(); users.User.Address1.Trim(); ef.AddUser(users.User); Session["MyKey"] = 0; Session["MyId"] = repository.Users.FirstOrDefault(u => u.Email == users.User.Email).UserId; Session["Name"] = users.User.UserName; if (Roles.IsUserInRole(users.User.Email, "1")) { Roles.RemoveUserFromRole(users.User.Email, "1"); } FormsAuthentication.SetAuthCookie(users.User.Email, false); ModelState.AddModelError("", "Registration Successfully "); return(Redirect(Url.Action("Index", "Home"))); } // If we got this far, something failed, redisplay form return(View(users)); }