这是课程
-Person -用户 -市 -国家 -address
人具有(地址)的复杂属性, 地址有复杂的属性(国家,城市) 类用户继承自Person类
情形: -
我想创建一个注册视图,其中我想为地址,国家/地区,城市分配值。我怎么能这样做。
以下是课程的详细信息
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; }
}
}
提前完成。
答案 0 :(得分:0)
如果右键单击控制器中注册页面的操作方法并选择添加视图,则在显示的对话框中,您可以选择使视图强类型 。选择你的User
课程,visual studio将支持许多所需的代码。
如果您在使用MVC时需要更多帮助,here是一个很好的起点。