0

我需要一些帮助才能将 where 规则放入 foreach 搜索中。我的目标是排除 customerOrder.ERPOrderNumber 以字母 E 开头的订单

我拥有的代码返回特定客户的所有订单。

预先感谢您的帮助。

 @foreach (var customerOrder in Model.CustomerOrders)
        { 
            <tr>
                <td class="mavo-order-date">@customerOrder.OrderDate.ToShortDateString()
                </td>
                <td class="mavo-status">@customerOrder.Status
                </td>
                <td class="mavo-order-number">
                    <a href="@Url.Action("OrderHistoryDetail", "Account", new { orderId = customerOrder.ERPOrderNumber })">@customerOrder.OrderNumber</a>
                </td>
                @if (Model.ShowErpOrderNumber)
                {
                    <td class="mavo-erp-order">@customerOrder.ERPOrderNumber
                    </td>
                }
                <td class="mavo-po">@customerOrder.CustomerPO
                </td>
                <td class="mavo-order-total">@customerOrder.OrderGrandTotal.ToCurrency()
                </td>
                <td class="mavo-view">
                    <a class="btn btnStyleA tbm5" href="@Url.Action("OrderHistoryDetail", "Account", new { orderId = customerOrder.ERPOrderNumber })">View Details</a>
                </td>
            </tr>
        }
4

1 回答 1

3

您可以if在循环中放置一条语句foreach,仅当订单号不以字母开头时才写出表格行E

@foreach (var customerOrder in Model.CustomerOrders)
{  
    @if(!customerOrder.ERPOrderNumber.StartsWith("E")) 
    {
       // Markup goes in here
    }
}

或者,您可以使用 LINQ 过滤CustomerOrders集合。

@foreach(var customerOrder in Model.CustomerOrders.Where(x => !x.StartsWith("E"))
于 2013-03-08T16:29:13.600 回答