簡體   English   中英

ASP.net MVC 5實體框架自動生成的代碼。 如何更改為更新用戶信息?

[英]ASP.net MVC 5 Entity framework Auto generated code. How to change to Update user information?

我一直在通過遷移為ASP.net MVC 5應用程序自動生成用戶信息。 該信息適用於注冊和登錄,但是我只能在登錄帳戶時更改密碼。 我希望能夠更新應用程序內的所有用戶信息。 以前,我只更改過用戶信息。 通過遷移過程,但是現在我想生成視圖和控制器以更新我的信息。 那我該怎么做呢? 如果有人對此有任何答案,請告訴我...

這是我的代碼:

[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();
}

確定我更改了一些信息的模型。

// 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; }

}

我正在使用ManageController更改用戶信息。

您可能可以看一下本教程 它顯示了用戶管理以及向用戶分配角色。

我希望您可以根據需要調整教程。 由於附加了解決方案的鏈接,因此不確定是否可以要求它作為答案。 因此,功勞歸功於撰寫本教程的人。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM