Pager

It will generate a pager with buttons that will redirect to the specified url by adding the page parameter in the query string

Rice Grains


PagerDemo/Index.cshtml
<table style="width: 300px;">
@{ foreach (var o in Model)
{
<tr>
<td>
@o.Name
</td>
<td>
@o.CategoryName
</td>
</tr>
}}
</table>
<br />

@(Html.Awe().Pager()
.Url(Url.Action("Index")) // url to go to
.Count((int)ViewData["count"]) // page count
.Page((int)ViewData["page"])) @*current page*@
Demos/Helpers/PagerDemoController.cs
using System.Linq;
using Microsoft.AspNetCore.Mvc;

using AweCoreDemo.Models;
using AweCoreDemo.Data;

namespace AweCoreDemo.Controllers.Demos.Helpers
{
public class PagerDemoController : Controller
{
public IActionResult Index(int page = 1)
{
const int PageSize = 1;
var pageCount = (DemoCache.Meals.Count() + PageSize - 1) / PageSize;

ViewData["page"] = page;
ViewData["count"] = pageCount;

return View(DemoCache.Meals.Skip((page - 1) * PageSize).Take(PageSize));
}
}
}



Comments