0

誰か助けてくれませんか?提供されているよりも多くのフィールドをアカウント コントローラーに追加したいと考えています。これらのフィールドもテーブルに表示したいと思います。Register クラスにフィールドを追加します。また、自動インクリメントを使用したいIDフィールドについてはわかりませんが、テーブルが表示されない場合の方法がわかりません。通常のデータベースでは、自動的に行われます。ありがとう。私の アカウントモデル:

public class ChangePasswordModel { [必須] [DataType(DataType.Password)] [Display(Name = "現在のパスワード")] public string OldPassword { get; 設定; }

    [Required]
    [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
    [DataType(DataType.Password)]
    [Display(Name = "New password")]
    public string NewPassword { get; set; }

    [DataType(DataType.Password)]
    [Display(Name = "Confirm new password")]
    [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
    public string ConfirmPassword { get; set; }
}

public class LogOnModel
{
    [Required]
    [Display(Name = "User name")]
    public string UserName { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [Display(Name = "Remember me?")]
    public bool RememberMe { get; set; }
}

public class RegisterModel
{
    [Required]
    public int ID { get; }

    [Required]
    [DataType(DataType.Text)]
    [Display(Name = "First Name")]
    public string FirstName { get; set; }

    [Required]
    [DataType(DataType.Text)]
    [Display(Name = "Last Name")]
    public string LastName { get; set; }

    [Required]
    [DataType(DataType.PhoneNumber)]
    [Display(Name = "Phone")]
    public string Phone { get; set; }

    [Required]
    [DataType(DataType.Text)]
    [Display(Name = "First line of address")]
    public string Address { get; set; }

    [DataType(DataType.Date)]
    [Display(Name = "DOB => dd/mm/yyyy")]
    public DateTime DateOfBirth { get; set; }

    [Required]
    [PostCode(ErrorMessage= "PostCode is not valid")]
    [Display(Name = "Post Code")]
    public string PostCode { get; set; }

    [Required]
    [Display(Name = "User name")]
    public string UserName { get; set; }

    [Required]
    [DataType(DataType.EmailAddress)]
    [Display(Name = "Email address")]
    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; }
}

public class PostCodeAttribute : RegularExpressionAttribute
{
    public PostCodeAttribute()
        : base(
            @"([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-
                hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-
                Yj-y][0-9]?[A-Za-z])))) {0,1}[0-9][A-Za-z]{2})")
    {
        ErrorMessage = "PostCode is invalid";
    }
}

次に、AccountController でテーブルに同じデータ フィールドを持つユーザーを作成できますが、メンバーシップにはこのオプションがありません。Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus) ;

4

2 に答える 2

0

これは「従来の」ASP.NET ですが、役に立つはずです

http://www.asp.net/web-forms/tutorials/security/membership/storing-additional-user-information-cs

(ここから、MySql および MVC 3 のメンバーシップを使用して登録フォームにフィールドを追加します)

于 2013-10-16T09:57:31.603 に答える
0

SimpleMembership (これは未来です) を検討し、独自のスキーマを使用してから、NuGet を使用して MVC 3 で使用することを検討してください。

于 2013-04-15T19:00:33.883 に答える