我的 Ilist 有问题,我无法循环遍历它,它总是抛出错误 Object reference not set to an instance of an object.. 这是我的观点.. 当我调试我的代码时,模型有一个值,但是当它转到foreach 它说 item.pillarofcultureteamlevel 没有设置..任何帮助
@model P247.Pres.MVC.ViewModel.SummaryTeamLevelViewModel
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<html>
<head>
<title></title>
</head>
<body>
<h2>Index</h2>
@{
var item = Model;
foreach (var pillar in item.pillarofcultureteamlevel)
{
var js = pillar.JobSecurityAndOverallCompensation;
}
}
</body>
</html>
这是我的控制器
public ActionResult Index()
{
_reportservice = new ReportService();
_pillarofcultureteamlevel = _reportservice.GetPillarsOfCultureTeamLevel(57);
_retentiondriverteamlevel = _reportservice.GetRentionDriversTeamLevel(57);
_employeeteamlevelsummarylist = _reportservice.GetEmployeeTeamLevelSummaryDTO(57);
summary = new SummaryTeamLevelViewModel(_pillarofcultureteamlevel, _retentiondriverteamlevel, _employeeteamlevelsummarylist);
return View(summary);
}
这是我的视图模型
public class SummaryTeamLevelViewModel
{
private IList<PillarsOfCultureTeamLevelDTO> _pillarofcultureteamlevel;
private IList<RetentionDriverTeamLevelDTO> _retentiondriverteamlevel;
private IList<EmployeeTeamLevelSummaryDTO> _employeeteamlevelsummarylist;
public SummaryTeamLevelViewModel(IList<PillarsOfCultureTeamLevelDTO> pillarofcultureteamlevel,
IList<RetentionDriverTeamLevelDTO> retentiondriverteamlevel,
IList<EmployeeTeamLevelSummaryDTO> employeeteamlevelsummarylist)
{
_pillarofcultureteamlevel = pillarofcultureteamlevel;
_retentiondriverteamlevel = retentiondriverteamlevel;
_employeeteamlevelsummarylist = employeeteamlevelsummarylist;
}
public IList<PillarsOfCultureTeamLevelDTO> pillarofcultureteamlevel { get; set; }
public IList<RetentionDriverTeamLevelDTO> retentiondriverteamlevel { get; set; }
public IList<EmployeeTeamLevelSummaryDTO> employeeteamlevelsummarylist { get; set; }
}