Reputation: 167
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";
}
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
foreach(var item in Model){
if (item.Device_DeviceID != null)
{
@Model.Count()
}
} }`
Upvotes: 0
Views: 4171
Reputation: 14133
@Model.Count(x => x.Condition == Value)
If your condition is the Device_DeviceID
not null, it became:
@Model.Count(x => x.Device_DeviceID != null)
Note that in your case, you don't need the foreach loop to do this.
Upvotes: 2