Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Filip Camara 3 posts 72 karma points
    Aug 12, 2021 @ 09:00
    Filip Camara
    0

    Missing Pagination for tag search

    No matter how many items are with a tag, when go to route : https://localhost:44325/test-blog/?t=tag_name the fields:
    totalItems and totalPages are 0

    the model is of type DotSee.SiteBlog.PageBlogListViewModel However if i manually go to https://localhost:44325/test-blog/?t=tag_name&page=2 it works I can rebuild this model properties in _PagePager.cshtml based on CustomMessagefrom where i can get the tag and search again on BlogRoot but It will be better to be corected in the controller. Thank you for your support.

  • Filip Camara 3 posts 72 karma points
    Aug 20, 2021 @ 17:37
    Filip Camara
    0

    I made a workaround in _PagePager as follows (maybe will be useful to somebody else):

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<IPageable>
    
    @using DotSee.Common;
    
    @{
        if (HttpContext.Current.Request.Url.Query.Contains("t="))
        {
            string tag = HttpContext.Current.Request.QueryString.Get("t");
            Umbraco.Web.PublishedModels.FolderArticlePosts posts = Umbraco.AssignedContentItem.Children.ToList()[0] as Umbraco.Web.PublishedModels.FolderArticlePosts;
            decimal ti = posts.Children<Umbraco.Web.PublishedModels.PageArticleItem>().Where(p => p.Tags.Contains(tag)).Count();
            Model.TotalPages = (int)Math.Ceiling(ti / Model.RecordsPerPage);
    
        }
    
    
        if (Model.TotalPages <= 1) { return; }
    
    
        int page = Model.Page;
        int recordsPerPage = Model.RecordsPerPage;
        int totalItems = Model.TotalItems;
        int totalPages = Model.TotalPages;
    
    
        if (page > totalPages) { page = totalPages; }
    
        string prevLink = Utils.UpdateQueryString(HttpContext.Current.Request, "page", (page - 1).ToString());
        string nextLink = Utils.UpdateQueryString(HttpContext.Current.Request, "page", (page + 1).ToString());
        int recordFrom = ((page - 1) * recordsPerPage + 1);
        int recordTo = ((page - 1) * recordsPerPage + recordsPerPage);
        if (recordTo > totalItems) { recordTo = totalItems; }
    
    }
    
    <div class="col-md-12 pagination-nav mt-60 mt-xs-30">
        <ul>
            @if (page > 1)
            {
                <li><a href="@prevLink"><i class="fa fa-angle-left"></i></a></li>
            }
            @for (int i = 1; i <= totalPages; i++)
            {
                string activeCss = (page == i) ? "active" : null;
    
                <li class="@activeCss"><a href="@Utils.UpdateQueryString(HttpContext.Current.Request,"page",i.ToString())">@i</a></li>
            }
            @if (page < totalPages)
            {
                <li><a href="@nextLink"><i class="fa fa-angle-right"></i></a></li>
            }
        </ul>
    </div>
    
Please Sign in or register to post replies

Write your reply to:

Draft