asp.net-mvc-4 – SimpleMembership – 向UserProfile添加电子邮件 – System.Data.SqlClient.SqlException:无效的列名称“Email”错误

前端之家收集整理的这篇文章主要介绍了asp.net-mvc-4 – SimpleMembership – 向UserProfile添加电子邮件 – System.Data.SqlClient.SqlException:无效的列名称“Email”错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我很确定我已经遵循了所有步骤,但似乎错过了一些东西.在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列.

解决方法

如果您使用的是默认连接,请点击查看 – >打开数据库.然后,Server Explorer将展开DefaultConnection.在Tables下,您将看到UserProfile表.首先将列添加到表中并更新数据库,然后将额外的字段添加到类中.
原文链接:https://www.f2er.com/aspnet/248346.html

猜你在找的asp.Net相关文章