【发布时间】:2018-11-30 08:36:17
【问题描述】:
我有一个包含如下部分列表的视图模型。我需要创建一个 ResponseEntryViewModel 列表,并在部分内添加部分和子部分,并在子部分内添加问题。
有什么建议吗?
public class ResponseEntryViewModel
{
public int TypeID { get; set; }
public string TypeName { get; set; }
public int User_ID { get; set; }
public List<SectionDataModel> Sections{ get; set; }
public ResponseEntryViewModel()
{
Sections = new List<SectionDataModel>();
}
public class SectionDataModel
{
public int SectionID { get; set; }
public string Name { get; set; }
public string Status { get; set; }
public int TypeId { get; set; }
public List<SubSectionModel> SubSections { get; set; }
public SectionDataModel()
{
SubSections = new List<SubSectionModel>();
}
}
public class SubSectionModel
{
public int SubSectionID { get; set; }
public string Name { get; set; }
public string Status { get; set; }
public int SectionId { get; set; }
public List<QuestionModel> QuestionsList { get; set; }
public SubSectionModel()
{
QuestionsList = new List<QuestionModel>();
}
}
public class QuestionModel
{
public int SubSectionID { get; set; }
public int QuestionID { get; set; }
public string Question { get; set; }
}
}
【问题讨论】:
-
到目前为止你尝试过什么?能否再具体说明一下你的问题,好像有点不清楚。
-
您不需要在 SubSectionModel 和 ResponseEntryViewModel 类上添加构造器
-
你应该避免在类中创建类。你必须知道如何使用
new来创建类的新对象并使用Add方法将对象添加到列表中。您尝试过使用它们吗? -
是的,我试过@ChetanRanpariya
-
你尝试的时候发生了什么?你能分享那个代码吗?你有什么错误吗?什么错误?
标签: c# asp.net-mvc list