.Net Core 2.1 中的寻呼机
Pager in .Net Core 2.1
我已经从 NuGet Link 添加了 ReflectionIT.Mvc.Paging,但我遇到了问题。
在控制器中我有 2 个方法,索引和组织。当我在 Orginizations 视图中并按下控制器中编号为“2”的页面时,转到索引而不是 Organizations 方法。
如何强制它继续我想要的方法或扩展此 @await this.Component.InvokeAsync("Pager", new { pagingList = this.Model })
以将方法名称作为参数传递?
控制器:
public IActionResult Index()
{
return View();
}
public async Task<IActionResult> Organizations(int page=1)
{
var userlist = _context.Users.Include(u => u.UserRoles).ThenInclude(u => u.Role).Where(o => o.UserRoles.All(r => r.Role.Name == "Company") && o.IsActive == true).AsNoTracking().OrderByDescending(o => o.Company);
var model = await PagingList.CreateAsync(userlist, 2, page);
return View(model);
}
查看:
@model ReflectionIT.Mvc.Paging.PagingList<CharityProject.Models.ApplicationUser>
@using ReflectionIT.Mvc.Paging
@addTagHelper *, ReflectionIT.Mvc.Paging
@{
ViewData["Title"] = "Organizations";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="container py-lg-5 py-md-5 py-sm-4 py-4">
<h2 class="pageTitles">Organizations</h2>
<div class="row">
<nav aria-label="NewsFeed navigation example">
@await this.Component.InvokeAsync("Pager", new { pagingList = this.Model })
</nav>
<br />
@foreach (var item in Model)
{
<div class="col-lg-4 col-md-6 col-sm-6 product-men women_two">
<div class="product-toys-info">
<div class="men-pro-item">
<div class="men-thumb-item">
@if (item.Logo != null)
{
<img src=@Url.Content(item.Logo.Replace("//","/").Replace("///","/")) class="img-thumbnail img-fluid" alt="">
}
<div class="men-cart-pro">
<div class="inner-men-cart-pro">
<a href=@Url.Action("OrganizationInfo","Home",new { id=item.Id}) class="link-product-add-cart">View</a>
</div>
</div>
</div>
<div class="item-info-product">
<div class="info-product-price">
<div class="grid_meta">
<div class="product_price">
<h4>
<a href=@Url.Action("OrganizationInfo","Home",new { id=item.Id})>@item.Company</a>
</h4>
<p>@item.Moto</p>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
}
<br />
<nav aria-label="NewsFeeds navigation example">
<vc:pager paging-list="@Model" />
</nav>
</div>
</div>
您可以将 Action 属性 设置为 PagingList 对象:
var model = await PagingList.CreateAsync(userlist, 2, page);
model.Action = "Organizations";
我已经从 NuGet Link 添加了 ReflectionIT.Mvc.Paging,但我遇到了问题。
在控制器中我有 2 个方法,索引和组织。当我在 Orginizations 视图中并按下控制器中编号为“2”的页面时,转到索引而不是 Organizations 方法。
如何强制它继续我想要的方法或扩展此 @await this.Component.InvokeAsync("Pager", new { pagingList = this.Model })
以将方法名称作为参数传递?
控制器:
public IActionResult Index()
{
return View();
}
public async Task<IActionResult> Organizations(int page=1)
{
var userlist = _context.Users.Include(u => u.UserRoles).ThenInclude(u => u.Role).Where(o => o.UserRoles.All(r => r.Role.Name == "Company") && o.IsActive == true).AsNoTracking().OrderByDescending(o => o.Company);
var model = await PagingList.CreateAsync(userlist, 2, page);
return View(model);
}
查看:
@model ReflectionIT.Mvc.Paging.PagingList<CharityProject.Models.ApplicationUser>
@using ReflectionIT.Mvc.Paging
@addTagHelper *, ReflectionIT.Mvc.Paging
@{
ViewData["Title"] = "Organizations";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="container py-lg-5 py-md-5 py-sm-4 py-4">
<h2 class="pageTitles">Organizations</h2>
<div class="row">
<nav aria-label="NewsFeed navigation example">
@await this.Component.InvokeAsync("Pager", new { pagingList = this.Model })
</nav>
<br />
@foreach (var item in Model)
{
<div class="col-lg-4 col-md-6 col-sm-6 product-men women_two">
<div class="product-toys-info">
<div class="men-pro-item">
<div class="men-thumb-item">
@if (item.Logo != null)
{
<img src=@Url.Content(item.Logo.Replace("//","/").Replace("///","/")) class="img-thumbnail img-fluid" alt="">
}
<div class="men-cart-pro">
<div class="inner-men-cart-pro">
<a href=@Url.Action("OrganizationInfo","Home",new { id=item.Id}) class="link-product-add-cart">View</a>
</div>
</div>
</div>
<div class="item-info-product">
<div class="info-product-price">
<div class="grid_meta">
<div class="product_price">
<h4>
<a href=@Url.Action("OrganizationInfo","Home",new { id=item.Id})>@item.Company</a>
</h4>
<p>@item.Moto</p>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
}
<br />
<nav aria-label="NewsFeeds navigation example">
<vc:pager paging-list="@Model" />
</nav>
</div>
</div>
您可以将 Action 属性 设置为 PagingList 对象:
var model = await PagingList.CreateAsync(userlist, 2, page);
model.Action = "Organizations";