我是新來的asp.net MVC 5身份框架,我嘗試直接更新我的詳細信息。直接轉發,我想要做的是將我的用戶信息更新到數據庫。 以前,我通過使用Migrations更改了用戶詳細信息,並使用實體框架爲了生成我的控制器,查看並自行建模。 但是,如何更新我的用戶詳細信息。我見過角色方法......但我從不明白,我該怎麼辦?沒有使用角色..因爲, 我想要更新UserManageController中所需的所有用戶信息...如何在ASP.net MVC 5應用程序上更新我的用戶帳戶數據
可能嗎?在不同的控制器中直接在生成的用戶帳戶上獲取值?如何檢索呢?
這裏是我的身份識別模型
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
public string userFname { get; set; }
public string userLname { get; set; }
public string address { get; set; }
public string userContactNo { get; set; }
public string commercialName { get; set; }
public string commercialAddress { get; set; }
public string commercialEmail { get; set; }
public string userType { 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;
}
}
這裏是我的Registeration模型
public class RegisterViewModel
{
[Required]
[Display(Name = "User First Name")]
public string userFname { get; set; }
[Required]
[Display(Name = "User Last Name")]
public string userLname { get; set; }
[Required]
[Display(Name = "User Address")]
public string address { get; set; }
[Required]
[Display(Name = "User Contact Number")]
public string userContactNo { get; set; }
[Display(Name = "Commercial Name")]
public string commercialName { get; set; }
[Display(Name = "Commercial Address")]
public string commercialAddress { get; set; }
[EmailAddress]
[Display(Name = "Commercial Email")]
public string commercialEmail { get; set; }
[Key]
[Required]
[EmailAddress]
[Display(Name = "Email")]
public string Email { 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]
public string userType { get; set; }
}
This [question](http://stackoverflow.com/questions/43362226/how-to-edit-a-user-in-asp-net-identity)看起來與你的相似。 – mmushtaq
請訪問下面的鏈接,它可能會幫助你:http://stackoverflow.com/questions/43362226/how-to-edit-a-user-in-asp-net-identity –
你檢查我的答案@HamunSunga? ?這是你期待的。 –