我很确定我已经遵循了所有步骤,但似乎错过了一些东西.在MVC4应用程序中使用simplemembership.将Email添加到UserProfile表以及Register和UserProfile模型中,将其添加到Register方法,但仍然收到错误.这是一些代码:
楷模:
public class UserProfile { public int UserId { get; set; } public string UserName { get; set; } public string Email { get; set; } } public class RegisterModel { [Display(Name = "Email Address")] [StringLength(20)] // [required] public string Email { get; set; } [Display(Name = "Date of Birth")] // [required] public DateTime DOB { get; set; } [required] [System.Web.Mvc.Remote("VerifyUserExists","Account",ErrorMessage="That Username is already taken.")] [Display(Name = "User name")] public string UserName { get; set; } [required] [StringLength(100,ErrorMessage = "The {0} must be at least {2} characters long.",MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "Password")] public string Password { get; set; } [DataType(DataType.Password)] [Display(Name = "Confirm password")] [Compare("Password",ErrorMessage = "The password and confirmation password do not match.")] public string ConfirmPassword { get; set; } }
控制器:
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName,model.Password,new { Email = model.Email }); WebSecurity.Login(model.UserName,model.Password); return RedirectToAction("Index","Home"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("",ErrorCodeToString(e.StatusCode)); } }
我不是试图使用电子邮件地址作为登录,只是想在注册步骤中抓取它,以便我可以发送自动确认电子邮件.
我已经尝试使用EF模型中包含的UserProfile表,并且使用它,没有区别.我已经确认DB中的表有一个Email列.