[英]ASP.net MVC 5 Entity framework Auto generated code. How to change to Update user information?
I have been auto generating user information for my ASP.net MVC 5 application through migrations. 我一直在通过迁移为ASP.net MVC 5应用程序自动生成用户信息。 This information works for Register and Login, but I can only change the password when log into an account .
该信息适用于注册和登录,但是我只能在登录帐户时更改密码。 I would like to be able to update all of the user information within the application.
我希望能够更新应用程序内的所有用户信息。 Previously I have only changed user information.
以前,我只更改过用户信息。 Through the migrations process, but now I want to generate the view and controller in order to update my information.
通过迁移过程,但是现在我想生成视图和控制器以更新我的信息。 So how can I do this?
那我该怎么做呢? If anybody know any answer about this, please let me know...
如果有人对此有任何答案,请告诉我...
Here is my code: 这是我的代码:
[HttpGet]
public ActionResult UpdateUserInfo()
{
return View();
}
[HttpPost]
public async Task<ActionResult> UpdateUserInfo(ApplicationUserManager model)
{
var role = new ApplicationUser()
{
Id = model.Id,
UserName = model.UserName
};
return View();
}
Identify Model which I changed some information. 确定我更改了一些信息的模型。
// 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;
}
Register View Model 注册视图模型
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; }
}
I am using ManageController to change user information. 我正在使用ManageController更改用户信息。
You can probably have a look at this tutorial . 您可能可以看一下本教程 。 It shows user management as well as assignment of roles to the users.
它显示了用户管理以及向用户分配角色。
I hope you can tweak the tutorial as per your need. 我希望您可以根据需要调整教程。 I am not sure if I can claim it as an answer as I've attached a link of a solution.
由于附加了解决方案的链接,因此不确定是否可以要求它作为答案。 So the credit goes to the guy who wrote this tutorial.
因此,功劳归功于撰写本教程的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.