我創建了一個表單,在該表單中使用 asp.net core 中的回圈從資料庫中獲取資料。我以該表單進行分頁,我只在頁面上顯示 5 個專案。但是現在我在該頁面上顯示了另一個資料,但我不想包含在分頁中。那么是否有任何ajax或其他解決方案
我的觀點:
@foreach(var item in Model)
{
<div class="embla__viewport">
<div class="embla__container">
<div class="embla__slide">
<div class="embla__slide__inner">
<img src="@item.pic1" />
<h2>@item.city | <a href="#">Map</a></h2>
<hr>
<div class="for_sale">
<a href="#">
</a>
<a href="#">
@item.price price
</a>
</div>
<hr>
<a href="#" class="arrow">
<svg class="home_svg" height="30px" viewBox="0 0 24 24" fill="#22577e"
xmlns="http://www.w3.org/2000/svg">
<path d="M13.5 8.25L17.25 12M17.25 12L13.5 15.75M17.25 12H6.75" stroke="#22577e"
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" />
</svg>
</a>
</div>
</div>
}
控制器:
public IActionResult Rent(int PageNumber = 1)
{
var data = rdb.GetDataHouse();
ViewBag.Totalpages = Math.Ceiling(data.Count()/5.0);
data = data.Skip((PageNumber - 1)*5).Take(5).ToList();
return View(data);
}
uj5u.com熱心網友回復:
您可以創建一個新PaginatedList類來處理分頁:
public class PaginatedList<T> : List<T>
{
public int PageIndex { get; private set; }
public int TotalPages { get; private set; }
public PaginatedList(List<T> items, int count, int pageIndex, int pageSize)
{
PageIndex = pageIndex;
TotalPages = (int)Math.Ceiling(count / (double)pageSize);
this.AddRange(items);
}
public bool HasPreviousPage => PageIndex > 1;
public bool HasNextPage => PageIndex < TotalPages;
public static async Task<PaginatedList<T>> CreateAsync(IQueryable<T> source, int pageIndex, int pageSize)
{
var count = await source.CountAsync();
var items = await source.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToListAsync();
return new PaginatedList<T>(items, count, pageIndex, pageSize);
}
}
具體的使用和實作可以參考
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/535344.html
上一篇:在URL中顯示復選框值
下一篇:減去兩個具有重復元素的陣列
