NealR
NealR

Reputation: 10689

Create condition in foreach loop in ASP MVC View

Is there syntax to create a condition in the 'foreach' loop used in the view page?

@foreach (var item in Model.Where(item.Status != "C") {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.TableName)
    </td>
    .
    .
    .

The syntax for this foreach is incorrect, does anyone have an idea what it should be? (The rest of the table is truncated)

Upvotes: 0

Views: 4958

Answers (2)

Mike Payne
Mike Payne

Reputation: 624

You're missing a parenthesis on the end of the foreach line:

@foreach (var item in Model.Where(item.Status != "C")) {

Upvotes: 1

Stoop
Stoop

Reputation: 1275

@foreach (var item in Model.Items.Where(i => i.Status != "C") {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.TableName)
    </td>

Upvotes: 2

Related Questions