.Net Core 2.1中的传呼机 [英] Pager in .Net Core 2.1
问题描述
我从NuGet中添加了ReflectionIT.Mvc.Paging 链接,但是我有一个问题.
I have added ReflectionIT.Mvc.Paging from NuGet Link but I have a problem.
在控制器中,我有2种方法:索引和组织.当我在组织"视图上并按控制器中数字为"2"的页面转到索引而不是在组织"方法上.
In a controller i have 2 methods, Index and Organizations. When I am on the view of Orginizations and press page with number "2" in controller goes to index and not on Organizations method.
如何强制它继续执行我想要的方法或扩展此@await this.Component.InvokeAsync("Pager", new { pagingList = this.Model })
以将方法名称作为参数传递?
How to force it to go on a method I want or to extend this @await this.Component.InvokeAsync("Pager", new { pagingList = this.Model })
to pass method name as parameter?
控制器:
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对象:
You can set the Action property to PagingList object :
var model = await PagingList.CreateAsync(userlist, 2, page);
model.Action = "Organizations";
这篇关于.Net Core 2.1中的传呼机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!