產品頁面上顯示的最大 (M) 產品數量(僅顯示前 M 個產品,其他 - 忽略;如果 M == 0,則顯示所有產品)
我該怎么做這個條件? 我需要在 ProductPageModel 或 Product.cshtml 中進行嗎?
產品.cshtml
@page
@model GetandTake.Pages.ProductModel
@{
}
<table class="table">
<thead>
<tr>
<th scope="col">ProductName</th>
<th scope="col">QuantityPerUnit</th>
<th scope="col">UnitPrice</th>
<th scope="col">UnitsInStock</th>
<th scope="col">UnitsOnOrder</th>
<th scope="col">ReorderLevel</th>
<th scope="col">Discontinued</th>
<th scope="col">Category</th>
<th scope="col">Supplier</th>
</tr>
</thead>
<tbody>
@foreach (var product in Model.Products)
{
<tr>
<td>@product.ProductName</td>
<td>@product.QuantityPerUnit</td>
<td>@product.UnitPrice</td>
<td>@product.UnitsInStock</td>
<td>@product.UnitsOnOrder</td>
<td>@product.ReorderLevel</td>
<td>@product.Discontinued</td>
<td>@product.Category</td>
<td>@product.Supplier</td>
</tr>
}
</tbody>
</table>
ProductModel product.cshtml.cs
public class ProductModel : PageModel
{
private readonly IProductService _productService;
public IEnumerable<ProductsDTO> Products { get; private set; }
public ProductModel(IProductService productService)
{
_productService = productService;
}
public void OnGet()
{
Products = _productService.GetAll();
}
}
uj5u.com熱心網友回復:
如果您只需要顯示第 M 個產品,只需添加.Take()方法System.Linq
public void OnGet()
{
Products = _productService.GetAll().take(M);
}
M您的最大產品編號在哪里。
僅當您不尋求分頁而僅顯示 N 個第一個產品時,這才可以接受。
由于這是一個業務規則,請嘗試將其放入C#檔案中,而不是.cshtml
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/517884.html
下一篇:紋理不會加載-Three.js
