我有一个包含这些字段的注册模型
public class Register
{
[Required]
[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; }
[Required]
[DataType(DataType.EmailAddress)]
[Display(Name = "Email Address")]
[EmailAddress]
public string Email { get; set; }
[Required]
[Display(Name = "Mobile Number")]
[StringLength(11, ErrorMessage = "The Mobile Number should be atleast 11 characters long")]
public string MobileNo { get; set; }
}
如何使用这些语句在UserProfile表中添加这些字段 WebSecurity.CreateUserAndAccount(model.UserName,model.Password);
答案 0 :(得分:1)
您可以使用CreateUserAndAccount
方法将匿名对象作为第三个参数,允许您传递与用户帐户关联的任意自定义字段:
WebSecurity.CreateUserAndAccount(
userName: model.UserName,
password: model.Password,
propertyValues: new
{
Email = model.Email,
MobileNo = model.MobileNo,
},
requireConfirmationToken: false
);