Asp.net mvc 4 如何为地址、国家和城市赋值
这里是课堂 -人 -使用者 -城市 -国家 -地址 此人具有(地址)的复杂属性, 地址具有(国家、城市)的复杂属性 类用户从Person类继承 情景:- 我想创建一个注册视图,我想在其中为地址、国家、城市赋值。我该怎么做呢 下面是课程的详细信息Asp.net mvc 4 如何为地址、国家和城市赋值,asp.net-mvc-4,Asp.net Mvc 4,这里是课堂 -人 -使用者 -城市 -国家 -地址 此人具有(地址)的复杂属性, 地址具有(国家、城市)的复杂属性 类用户从Person类继承 情景:- 我想创建一个注册视图,我想在其中为地址、国家、城市赋值。我该怎么做呢 下面是课程的详细信息 public class Person { public Person() { } private string name; public string Name { get { return
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; }
}
}
公共类人物
{
公众人士()
{ }
私有字符串名称;
公共字符串名
{
获取{返回名称;}
设置{name=value;}
}
私人性别;
公共虚拟性别
{
获取{返回性别;}
设置{gender=value;}
}
私人ICollection联系人号码;
公共虚拟ICollection联系人号码
{
获取{return contactNumber;}
设置{contactNumber=value;}
}
私人地址;
公共虚拟地址
{
获取{返回地址;}
设置{address=value;}
}
私人日期出生日期时间;
公共日期时间出生日期
{
获取{返回出生日期;}
设置{dateOfBirth=value;}
}
私有字符串图片;
公共字符串图片
{
获取{返回图片;}
设置{picture=value;}
}
}
公共类用户:Person
{
公共用户():base()
{ }
私人ICollection角色;
公共虚拟ICollection角色
{
获取{返回角色;}
设置{roles=value;}
}
私有int-id;
公共整数Id
{
获取{return id;}
设置{id=value;}
}
私人字符串电子邮件;
[必需()]
[正则表达式(@“\w+([-+.]\w+*@\w+([-.]\w+*\)。\w+([-.]\w+*”)]
[显示(Name=“电子邮件地址”)]
公共字符串电子邮件
{
获取{返回电子邮件;}
设置{email=value;}
}
私有字符串loginId;
[必需()]
[显示(Name=“登录”)]
公共字符串LoginId
{
获取{return loginId;}
设置{loginId=value;}
}
私有字符串密码;
[必需()]
[显示(Name=“密码”)]
[数据类型(数据类型.密码)]
公共字符串密码
{
获取{返回密码;}
设置{password=value;}
}
私有字符串重密码;
[必需()]
[显示(Name=“确认密码”)]
[比较(“密码”)]
公共字符串重密码
{
获取{return repassword;}
设置{repassword=value;}
}
私密字符串隐秘问题;
[必需()]
[显示(Name=“机密问题”)]
公共字符串秘密问题
{
获取{返回secretQuestion;}
设置{secretQuestion=value;}
}
私人字符串秘书;
[必需()]
[显示(Name=“应答”)]
公共字符串秘书长
{
获取{return secretAnswer;}
设置{secretAnswer=value;}
}
私有字符串地址;
[显示(Name=“Image”)]
公共字符串地址
{
获取{return photoUrl;}
设置{photoUrl=value;}
}
}
公营国家
{
公共国家()
{ }
私有int-id;
公共整数Id
{
获取{return id;}
设置{id=value;}
}
私有字符串名称;
公共字符串名
{
获取{返回名称;}
设置{name=value;}
}
//私有字符串flagUrl;
}
公营城市
{
公共城市()
{ }
私有int-id;
公共整数Id
{
获取{return id;}
设置{id=value;}
}
私有字符串名称;
公共字符串名
{
获取{返回名称;}
设置{name=value;}
}
私人国家;
公共虚拟国家
{
获取{返回国家;}
设置{country=value;}
}
}
Thanx提前。如果右键单击控制器中注册页面的操作方法,并在出现的对话框中选择“添加视图”,则可以选择将视图设置为强类型。选择您的
用户
类,VisualStudio将构建大量所需的代码
如果您在使用MVC时需要更多帮助,那么这是一个很好的开始。您是否在询问如何创建一个视图,以将所有这些类作为模型包含在内?