【发布时间】:2017-04-12 09:14:29
【问题描述】:
我是 asp.net MVC 5 身份框架的新手,我正在尝试直接更新我的详细信息。 直截了当,我想做的是将我的用户信息更新到数据库中。 以前,我使用 Migrations 更改了我的用户详细信息,并使用实体框架来生成我的控制器、视图和模型。 但是,如何更新我的用户详细信息。我看过角色方法..但我不明白,我该怎么办?不使用角色..因为, 我想在 UserManageController 中更新所有需要的用户信息...
有可能吗?在不同的控制器中并直接在生成的用户帐户上获取值?那怎么找回呢?
这是我的身份模型
// 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;
}
}
这是我的注册模型
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; }
}
【问题讨论】:
-
这个question 看起来和你的很像。
-
请访问以下链接,它可能对您有所帮助:stackoverflow.com/questions/43362226/…
-
你检查了我的答案@HamunSunga 吗?这是你所期待的。
-
@Basanta Matia - 是的,但我想要直接访问,而不是使用不同的模型......我问,我可以获取自动生成的模型类以生成我的编辑吗?有可能吗?
标签: asp.net-mvc entity-framework asp.net-identity