Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Block - PagedListPager Issue

Dev
Dev
Vote:
 

Hi,

I am new to Episerver and really hope someone can help me because I am lost at the moment.

I created an Articles Block with generates a list of news articles. A user can drag and drop the block on any page, and enter the number of articles it requires. I am trying to add pagination to this block to show if articles are more than suppose 10. It generates and shows but 2nd page is blank

public override ActionResult Index(ArticlesBlock currentBlock)
        {
            var temp = Request.QueryString["page"];
            var articles = FindArticlePages(currentBlock);          

            if (currentBlock.IsFeaturedArticles)
            {
                articles = articles.Where(x => x.IsFeatured);
            }

            int pageSize = currentBlock.Count == 0 ? 10 : currentBlock.Count;
            //int pageIndex = 1;
            int pageIndex = !string.IsNullOrWhiteSpace(temp) ? Convert.ToInt32(temp) : 1;

            //int pageIndex = page.HasValue ? Convert.ToInt32(page) : 1;

            var model = new ArticlesBlockViewModel(currentBlock, EpiServerDependencies)
            {
                
                ArticlePagesList = articles.ToPagedList(pageIndex, pageSize),
                PageNumber = pageIndex  
            };            
		return PartialView("", model);
        }
View is as below

@Html.PagedListPager(Model.ArticlePagesList, page => Url.Action("Index", new { page }))

Now, I do get the all articles as per the count entered and also the pagination like 1234>> with URLs but face the below issues

  1. The block is on page websiteurl/en/standard1/ but when I click on number 2 it has URL as websiteurl/viewfilename/Index?page=2 and not websiteurl/en/standard1/?page=2
  2. All pages that show websiteurl/viewfilename/Index?page=2 have no data, it is empty

I am using Find to get all articles

pages = SearchClient.Instance.Search<ArticlePage>()
                .Filter(x => x.Ancestors().Match(articleRoot.ID.ToString()))
              .OrderByDescending(x => x.StartPublish)
                .GetContentResult();

Would be grateful for any help or advice.

Thank you

#253238
Apr 14, 2021 18:40
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.