计算多个列表中的元素总数

我对asp.net开发非常陌生。我想为主页制作一个计数器视图,我想拥有4个differents表的4个计数器。例如,如果我有一个新的注册,我希望视图通过455到456。

这是我的剃刀视图:

@model XXX.Models.HomeCounter

<h4><strong>@Model.TotalRegistrations</strong></h4>
<h4><strong>@Model.TotalGraduates</strong></h4>
<h4><strong>@Model.TotalCohorts</strong></h4>
<h4><strong>@Model.TotalFacilities</strong></h4>

这是我在控制器中尝试执行的操作(我不知道我需要什么,而不是“ ????”:

 public actionResult Index()
        {
            var counterViewModel = new CodeboxxSchoolCounter { Registrations = ????,Facilities = ?????,Cohorts = ????,Graduated_Students = ???};

            return View(counterViewModel );
        }

这是我在模型中尝试的方法,但其他模型中已经存在我的班级注册,毕业学生,同类群组和设施:

public class HomeCounter
{
    public IEnumerable<Registrations> Registrations { get; set; }
    public int TotalRegistrations { get { return Registrations.Count(reg => reg.ID); } }
    public IEnumerable<Graduated_Students> Graduated_Students { get; set; }
    public int TotalGraduates { get { return Graduated_Students.Count(grad => grad.ID); } }
    public IEnumerable<Facilities> Facilities { get; set; }
    public int TotalFacilities { get { return Facilities.Count(fac => fac.ID); } }
    public IEnumerable<Cohorts> Cohorts { get; set; }
    public int TotalCohorts { get { return Cohorts.Count(coh => coh.ID); } }

}

public class Registrations
{
    public bool ID { get; set; }
}
public class Graduated_Students
{
    public bool ID { get; set; }
}
public class Facilities
{
    public bool ID { get; set; }
}
public class Cohorts
{
    public bool ID { get; set; }
}
koten443322 回答:计算多个列表中的元素总数

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3063932.html

大家都在问