C# 在视图中使用多个模型类
我有模型课:C# 在视图中使用多个模型类,c#,asp.net-mvc,C#,Asp.net Mvc,我有模型课: public class CV { public PrivateInformation privateInformation { get; set; } public List<Education> education { get; set; } public List<WorkingExperience> workingExperience { get; set; } } public class PrivateInformation { publ
public class CV
{
public PrivateInformation privateInformation { get; set; }
public List<Education> education { get; set; }
public List<WorkingExperience> workingExperience { get; set; }
}
public class PrivateInformation
{
public string Name { get; set; }
public DateTime BirthDate { get; set; }
public string Address { get; set; }
public string PhoneNumber { get; set; }
public string Email { get; set; }
}
public class Education
{
public string UniversityName { get; set; }
public string Faculty { get; set; }
public string Specialization { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public bool OnGoing { get; set; }
}
public class WorkingExperience
{
public string CompanyName { get; set; }
public string Position { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public bool OnGoing { get; set; }
}
公共类CV
{
公共私有信息私有信息{get;set;}
公共列表教育{get;set;}
公共列表工作经验{get;set;}
}
公共类私有信息
{
公共字符串名称{get;set;}
公共日期时间出生日期{get;set;}
公共字符串地址{get;set;}
公共字符串PhoneNumber{get;set;}
公共字符串电子邮件{get;set;}
}
公营教育
{
公共字符串UniversityName{get;set;}
公共字符串{get;set;}
公共字符串专门化{get;set;}
公共日期时间起始日期{get;set;}
公共日期时间结束日期{get;set;}
公共布尔值{get;set;}
}
公共课工作经验
{
公共字符串CompanyName{get;set;}
公共字符串位置{get;set;}
公共日期时间起始日期{get;set;}
公共日期时间结束日期{get;set;}
公共布尔值{get;set;}
}
还有其他的课程。我想让那个用户从一个页面输入全部信息。(大学可以超过1个,因为我有工作经验)
但是,当我在视图中以模范班的身份制作简历时,我无法获得教育。Name
我该怎么做?或者还有其他方法吗?常用的方法是创建ViewModel类 基本上,创建一个包含视图所需的所有属性的类,并使用它
如果您想使用其他属性,只需创建整个模型的视图模型,并初始化其中其他类的属性
Public class PrivateInformationViewModel
{
ublic string UniversityName { get; set; }
public string Faculty { get; set; }
public string Specialization { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public bool OnGoing { get; set; }
public Education EModel {get; set;}
}
现在,通过此视图模型,您还可以访问教育属性。您如何访问它?(
Education
是一个集合,所以你需要使用索引器)@StephenMuecke是的,我无法访问。我不知道我该怎么做,因为我被问到了。我知道我的方法不好,你还没有显示你的代码!(因此,这不是一项代码编写服务——它是用来帮助您纠正代码错误的)这正是OP的class CV
的功能!这和OP的问题毫无关系。但如果我想使用另一个类的列表,我该怎么办?