1.8.6.Adding Profile Data
1.Add Driving license to identity.cs
public class ApplicationUser : IdentityUser { [Required] [StringLength(255)] public string DrivingLicense { get; set; } public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here return userIdentity; } }
2.Update migration files, type:
add-migration "add driving license"
3.Update database, type:
update-database
4.Modify accountViewModel.cs
public class RegisterViewModel { [Required] [Display(Name = "Driving Liciense")] public string DrivingLicense { get; set; }
5.Modify accountController.cs
[HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, DrivingLicense = model.DrivingLicense };
5.Modify Register.cshtml
<div class="form-group"> @Html.LabelFor(m => m.DrivingLicense, new { @class = "col-md-2 control-label" }) <div class="col-md-10"> @Html.TextBoxFor(m => m.DrivingLicense, new { @class = "form-control" }) </div> </div>
Last updated
Was this helpful?