无效的列名称'长度'已编辑MVC 4成员资格

jac*_*oke 2 c# linq ef-code-first asp.net-mvc-4

我正在尝试添加到MVC 4开箱即用的会员资格.

public ActionResult Register(RegisterModel model)
{
    if (ModelState.IsValid)
    {
        // Attempt to register the user
        try
        {
            WebSecurity.CreateUserAndAccount(model.UserName, model.Password, model.Mobile);
            //I added model.Mobile
            WebSecurity.Login(model.UserName, model.Password);
            return RedirectToAction("Index", "Home");
        }
        catch (MembershipCreateUserException e)
        {
            ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我改变了模型

public class RegisterModel
{
    // Username and password methods

    public string Mobile { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我还将它添加到UserProfile模型中.我收到一个SqlException,我只是没有看到连接.这似乎是一个简单的错误但是.设置DB Nvarchar(MAX)以尝试避免此错误.

Invalid column name 'Length' 
Run Code Online (Sandbox Code Playgroud)

El *_*ong 6

它实际上是抛出错误,因为它需要一个附加属性的字典 - 尝试:

WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new{model.Mobile}, false)
Run Code Online (Sandbox Code Playgroud)

这假设您在UserProfileTable中有一个名为Mobile的列.如果要指定其他列名:

WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new{YourColumnName = model.Mobile}, false)
Run Code Online (Sandbox Code Playgroud)