使用自定义URL替换pagedlist生成的URL中的查询字符串 [英] Replacing the query string in the URL generated by pagedlist with custom URL

查看:63
本文介绍了使用自定义URL替换pagedlist生成的URL中的查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am using PagedList in a fully functional pager and it is generating the query string for the indexed pages as expected. 

I wanted to know if there is a way the URL could be customized to eliminate the query string and add another Route parameter instead.
 
The following is my View :- 
   <pre>
    @model PagedList.Core.IPagedList<ActionAugerMVC.Models.Review>
    @using PagedList.Core.Mvc;
    @addTagHelper *, PagedList.Core.Mvc

    <div id='Paging' style="text-align:center">
         Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
         <pager class="pager-container" list="@Model" 
                options="@PagedListRenderOptions.TwitterBootstrapPager" 
                asp-action="Index" asp-controller="Review" />
    </div> 



这是我的控制器动作: -




And here is my Controller Action :-

[Route("Reviews/calgary-tech-reviews")]
public IActionResult Index(int? page)
{
    int pageSize = 10;
    int pageIndex = 1;
    pageIndex = page.HasValue ? Convert.ToInt32(page) : 1;

    var review = unitOfWork.ReviewRepository.GetAll();
    return View(review.OrderByDescending(m=> m.Date).ToPagedList(pageIndex,pageSize));
}



当前网址如下所示: -


The current URL looks like this :-

http://localhost:63613/Reviews/calgary-tech-reviews?page=2



我希望它看起来像这样: -


And I want it to look like this :-

http://localhost:63613/Reviews/calgary-tech-reviews/page-2/



OR


OR

http://localhost:63613/Reviews/page-2/calgary-tech-reviews/



任何帮助都会受到赞赏,因为我还是新手!

再次感谢!



我尝试了什么:



我试图调查PagedList的实现和文档,看看我如何覆盖它。我确实发现所有页面都是作为标签生成的,并附加了quyerystring,因此我试图想出一种方法来撤销它。

推荐答案

它可能有所帮助:
[Route("Reviews/calgary-tech-reviews/page={page:int}")]


这篇关于使用自定义URL替换pagedlist生成的URL中的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆