I am trying to add to the MVC 4 out of the box membership.
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));
}
}
}
I changed the model
public class RegisterModel
{
// Username and password methods
public string Mobile { get; set; }
}
I also added it to the UserProfile Model. I am getting a SqlException and i just don't see the connection. It seems like such a simple error but. The DB is set to Nvarchar(MAX) which is to try to avoid this error.
Invalid column name 'Length'
It's actually throwing the error because it expects a dictionary of additional properties - try:
WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new{model.Mobile}, false)
This assumes that you have a column called Mobile in the UserProfileTable. If you wanted to specify a different column name:
WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new{YourColumnName = model.Mobile}, false)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With