简体   繁体   English

ASP.net MVC 5实体框架自动生成的代码。 如何更改为更新用户信息?

[英]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.

相关问题 在实体框架中如何在mvc asp.net中提取过程信息 - In Entity Framework How To Extract Procedure Information In mvc asp.net ASP.NET MVC和实体框架:生成的数据验证 - ASP.NET MVC and Entity Framework: Generated Data Validation 具有相关实体的ASP.NET Mvc中的实体框架更新错误 - Entity Framework Update Error in ASP.NET Mvc with related entity 将用户定向到 ASP.Net MVC 应用程序中的另一个页面会导致自动生成的代码出现语法错误 - Directing user to another page in ASP.Net MVC application leads to syntax error in auto-generated code 如何在ASP.NET MVC 5和身份(实体框架优先)中将用户链接到另一个用户 - How can I link a user to another user in ASP.NET MVC 5 and Identity (Entity Framework Code-First) ASP.NET MVC如何访问Entity Framework生成的外键? - ASP.NET MVC How to access Entity Framework generated foreign key? ASP.net MVC实体框架更新多对多关系 - ASP.net MVC Entity framework update Many to Many relationship 使用实体框架和ASP.NET MVC5更新记录 - Update records using Entity Framework and ASP.NET MVC5 使用实体框架在ASP.NET MVC中获取特定的用户数据 - Getting specific user data in ASP.NET MVC with Entity Framework 注册为用户失败... Asp.net mvc实体框架 - Registering as user fails… Asp.net mvc entity framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM