Добавлена постраничная навигация средствами X.PagedList

Добавлены данные в бд.
Переработан экшен в контроллере FilmsController для обработки постраничной навигации
Стилизованы кнопки постраничной навигации.
parent 9b4d9e76
......@@ -74,6 +74,8 @@
<e p="favicon.ico" t="Include" />
<e p="images" t="Include">
<e p="Posters" t="Include">
<e p="The Lord Of The Rings_The_Lord_of_the_Rings._The_Fellowship_of_the_Ring_—_movie.jpg" t="Include" />
<e p="Иван Васильевич меняет профессию_Иван_Васильевич_меняет_профессию_(постер).jpg" t="Include" />
<e p="Три мушкетера_Три_мушкетёра_(2013).jpg" t="Include" />
</e>
</e>
......
This diff is collapsed.
......@@ -12,6 +12,7 @@
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.1.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.10" />
<PackageReference Include="X.PagedList.Mvc.Core" Version="8.0.7" />
</ItemGroup>
<ItemGroup>
......
......@@ -9,6 +9,7 @@ using Cinema.Services;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using X.PagedList;
namespace Cinema.Controllers
{
......@@ -31,10 +32,15 @@ namespace Cinema.Controllers
_userManager = userManager;
}
public IActionResult Index()
public IActionResult Index(int? page)
{
List<Film> films = _db.Films.OrderBy(f => f.UpdatedAt).ToList();
return View(films);
List<Film> films = _db.Films.OrderByDescending(f => f.UpdatedAt).ToList();
var pageNumber = page ?? 1;
var onePageOfFilms = films.ToPagedList(pageNumber, 21);
ViewBag.FilmPage = onePageOfFilms;
return View();
}
public IActionResult About(int id)
......
@model List<Film>
@using X.PagedList
@using X.PagedList.Mvc.Core
@{
ViewBag.Title = "Главная страница Все фильмы";
Layout = "_Layout";
}
@if (@Model.Count == 0)
@if (@ViewBag.FilmPage.Count == 0)
{
<h3>Список фильмов Пуст</h3>
}
......@@ -14,7 +15,7 @@ else
<h2>Список загруженных фильмов</h2>
<div class="d-flex align-items-stretch flex-wrap justify-content-between">
@foreach (var film in @Model)
@foreach (var film in @ViewBag.FilmPage)
{
<div class="film-card">
<a asp-action="About" asp-route-id="@film.Id">
......@@ -33,3 +34,4 @@ else
}
</div>
}
@Html.PagedListPager( (IPagedList)ViewBag.FilmPage, page => Url.Action("Index", new { page }) )
No preview for this file type
......@@ -80,3 +80,10 @@ img{
width: 32%;
margin-bottom: 15px;
}
.pagination-container .pagination li{
padding: 5px 12px;
border: 1px solid silver;
border-radius: 5px;
margin: 0 3px;
display: block;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment