I’m returning quite a few rows on a view page. I’m wanting to show several tables, each being a subset of the full results. I have a foreach loop, and I’m wondering how I filter the results so “ResponseCode > 400” and “ExtFlag = 1”
@foreach (var res in Model.LinkCheckerResults)<br>
{
<tr>
<td>
@Html.DisplayFor(model => res.SourceURL)<br>
</td>
<td>
@Html.DisplayFor(model => res.TargetURL)
</td>
<td>
@Html.DisplayFor(model => res.Response)
</td>
</tr>
}
Many Thanks.
Assuming
ResponseCodeandExtFlagare members of whateverLinkCheckerResultsreturns, you can do this as you normally would in aforeachloop in C#.With LINQ:
Or an
ifstatement:Or (the true MVC way) provide the collection pre-filtered as a
ViewData/ViewBagproperty.