我在使用Asp.NET Core 2.2项目时使用ReflectionIT.Mvc.Paging进行分页时遇到问题

问题描述 投票:0回答:2

分页在首页上工作正常,它也可以获取结果。

但是问题是,只要我单击分页中的任何页码(假设我单击了2),它就会搜索Index.cshtml文件,而不是转到该特定控制器的方法。

enter image description here

下面的代码在GetCustomers IndexHomeController'. But it will search forHomeController内部的方法method of的视图中

 <nav>
    @await this.Component.InvokeAsync(typeof(ReflectionIT.Mvc.Paging.PagerViewComponent), new { pagingList = this.Model }))
 </nav>

我应该在代码中进行哪些更改,以便将其转到方法GetCustomers

c# asp.net-core asp.net-core-2.2
2个回答
0
投票

您可以将Action属性设置为您的PagingList对象,如下所示:

public async Task<IActionResult> Index(int page = 1)
{
      var qry = _context.Customer.AsNoTracking().OrderBy(c => c.Name);
      var model = await PagingList.CreateAsync(qry, 10, page);
      model.Action = "GetCustomers";
      return View(model);            
}

0
投票

我认为您在视图中错过了一些代码,

尝试将其更改为

<nav>
@await this.Component.InvokeAsync(typeof(ReflectionIT.Mvc.Paging.PagerViewComponent), 
new { pagingList = this.Model }))
</nav>

收件人

<nav aria-label="Suppliers navigation example">
@await this.Component.InvokeAsync("Pager", new { pagingList = this.Model })
</nav>

并将其添加到您的控制器中

public async Task<IActionResult> Index(int page = 1) {
var qry = _context.Suppliers.AsNoTracking().OrderBy(p => p.CompanyName);
var model = await PagingList.CreateAsync(qry, 10, page);
return View(model);

}

以及更多详细信息,请参考此URL

https://www.reflectionit.nl/blog/2017/paging-in-asp-net-core-mvc-and-entityframework-core

© www.soinside.com 2019 - 2024. All rights reserved.