0

How do I count rows in a table that meet a condition. Below counts every row regardless of whether or not a condition is met.

model IEnumerable<Sales1.Models.UserProfile>

@{
ViewBag.Title = "Details";
}

Total Sales Figures

@using (Html.BeginForm()) {
@Html.ValidationSummary(true)

foreach(var item in Model){

    if (item.Device_DeviceID != null)
    {
        @Model.Count()


    }

} }`

4

1 回答 1

2
@Model.Count(x => x.Condition == Value)

如果您的条件Device_DeviceID不为空,则变为:

@Model.Count(x => x.Device_DeviceID != null)

请注意,在您的情况下,您不需要 foreach 循环来执行此操作。

于 2013-06-13T15:58:15.533 回答