0

这里是类

-Person -User -City -Country -Address

Person 具有 (Address) 的复杂属性,Address 具有 (Country , City) 类的复杂属性 User 从 Person 类继承

设想:-

我想创建一个注册视图,我想在其中将值分配给 Address 、 country 、 city 。我该怎么做。

以下是课程详情

public class Person
{
    public Person()
    { }

    private string name;

    public string Name
    {
        get { return name; }
        set { name = value; }
    }
    private Gender gender;

    public virtual Gender Gender
    {
        get { return gender; }
        set { gender = value; }
    }
    private ICollection<ContactNumber> contactNumber;

    public virtual ICollection<ContactNumber> ContactNumber
    {
        get { return contactNumber; }
        set { contactNumber = value; }
    }


    private Address address;

    public virtual Address Address
    {
        get { return address; }
        set { address = value; }
    }


    private DateTime dateOfBirth;

    public DateTime DateOfBirth
    {
        get { return dateOfBirth; }
        set { dateOfBirth = value; }
    }

    private string picture;

    public string Picture
    {
        get { return picture; }
        set { picture = value; }
    }
}

public class User : Person
{
    public User() : base()
    { }

    private ICollection<Role> roles;

    public virtual ICollection<Role> Roles
    {
        get { return roles; }
        set { roles = value; }
    }

    private int id;

    public int Id
    {
        get { return id; }
        set { id = value; }
    }

    private string email;                        

    [Required()]
    [RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*")]
    [Display(Name = "Email Address")]
    public string Email
    {
        get { return email; }
        set { email = value; }
    }

    private string loginId;

    [Required()]
    [Display(Name = "Login")]
    public string LoginId
    {
        get { return loginId; }
        set { loginId = value; }
    }

    private string password;

    [Required()]
    [Display(Name = "Password")]
    [DataType(DataType.Password)]
    public string Password
    {
        get { return password; }
        set { password = value; }
    }
    private string repassword;

    [Required()]        
    [Display(Name = "Confirm Password")]        
    [Compare("Password")]               
    public string Repassword    
    {
      get { return repassword; }
      set { repassword = value; }
    }
    private string secretQuestion;

    [Required()]
    [Display(Name = "Secret Question")]
    public string SecretQuestion
    {
        get { return secretQuestion; }
        set { secretQuestion = value; }
    }
    private string secretAnswer;

    [Required()]
    [Display(Name = "Answer")]
    public string SecretAnswer
    {
        get { return secretAnswer; }
        set { secretAnswer = value; }
    }

    private string photoUrl;

    [Display(Name = "Image")]
    public string PhotoUrl
    {
        get { return photoUrl; }
        set { photoUrl = value; }
    }
}


public class Country
{
    public Country()
    { }

    private int id;

    public int Id
    {
        get { return id; }
        set { id = value; }
    }

    private string name;

    public string Name
    {
        get { return name; }
        set { name = value; }
    }
    //private string flagUrl;
}

public class City
{
    public City()
    { }

    private int id;

    public int Id
    {
        get { return id; }
        set { id = value; }
    }
    private string name;

    public string Name
    {
        get { return name; }
        set { name = value; }
    }
    private Country country;

    public virtual Country Country
    {
        get { return country; }
        set { country = value; }
    }
}

提前感谢。

4

1 回答 1

0

如果您在控制器中右键单击您的注册页面的操作方法并选择Add View在出现的对话框中,您可以选择将视图设置为强类型。选择您的User课程,Visual Studio 将搭建大量所需的代码。

如果您在使用 MVC 时需要更多帮助,这里是一个不错的起点。

于 2013-05-27T18:57:05.733 回答