Copied to clipboard

Flag this post as spam?

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


  • Matt 170 posts 422 karma points
    Jan 09, 2019 @ 14:45
    Matt
    0

    Pageination code not working

    Hello all,

    I hope someone can help, I'm trying to add pageination code to my website I've added the following code;

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.GuideList>
        @using ContentModels = Umbraco.Web.PublishedContentModels;
        @{
        Layout = "Master.cshtml";
    
        int pageSize = 3; // How many items per page
        int page; // The page we are viewing
    
        /* Set up parameters */
    
        if (!int.TryParse(Request.QueryString["page"], out page))
        {
        page = 1;
        }
    
        /* This is your basic query to select the nodes you want */
    
        var nodes = Model.Content.Children.Where(x => x.DocumentTypeAlias == "GuideDocument").OrderBy("CreateDate desc");
    
        int totalNodes = nodes.Count();
        int totalPages = (int)Math.Ceiling((double)totalNodes / (double)pageSize);
    
        /* Bounds checking */
    
        if (page > totalPages)
        {
        page = totalPages;
        }
        else if (page < 1)
        {
        page = 1;
        }
    
        }
    
    
    
        <div class="body-section">
            <div class="body-container w-container">
                <h1 class="home-page-heading">@Model.Content.Name</h1>
    
                  @foreach(var item in nodes.Skip((page-1)*pageSize).Take(pageSize))
        {
    
                foreach(var pDocument in Model.Content.Children())
                {
                var documentPicker = pDocument.GetPropertyValue<IPublishedContent>
                    ("documentPicker");
                    var linkPicker = pDocument.GetPropertyValue<string>
                        ("UrlPicker");
    
                        <div class="faq-wrapper">
                            <div class="guidandpolicies-wrapper">
                                <div class="w-row">
                                    <div class="w-col w-col-2">
    
    
                                        @{
                                        if (documentPicker != null)
                                        {
                                        <a href="@documentPicker.Url" target="_blank" class="document-link-block w-inline-block"><img src="/images/policies_image_1policies_image.png"></a>
                                        }else if(!string.IsNullOrEmpty(linkPicker)){
                                        <a href="@linkPicker" target="_blank" class="document-link-block w-inline-block"><img src="/images/policies_image_1policies_image.png"></a>
    
                                        }
                                        }
    
    
    
                                    </div>
                                    <div class="w-col w-col-10">
                                        <div class="guidanceandpolicies-info-div">
                                            <h5 class="gnp-title">
    
                                                @{
                                                if (documentPicker != null)
                                                {
                                                <a href="@documentPicker.Url" target="_blank" class="document-link-text">@pDocument.GetPropertyValue("documentTitle")</a>
                                                }else if(!string.IsNullOrEmpty(linkPicker)){
                                                <a href="@linkPicker" target="_blank" class="document-link-text">@pDocument.GetPropertyValue("documentTitle")</a>
                                                }
                                                }
    
    
                                            </h5>
                                            <div class="gnp-document-info">@pDocument.GetPropertyValue("documentDescription")</div>
    
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                 }       
             {
            if (totalPages > 1)
            {
                <div class="center">
                <div class="pagination">
                        @if (page > 1)
                        {
                            <a href="?page=@(page-1)">Prev</a>
                        }
                        @for (int p = 1; p < totalPages + 1; p++)
                        {
                        <a href="?page=@p" class="@(p == page ? "active" : string.Empty)">@p</a>
                        }
                        @if (page < totalPages)
                        {
                            <a href="?page=@(page+1)">Next</a>
                        }
                </div>
                </div>
    
                        }
                        }
                        }
            </div>
        </div>
    

    But for some reason it doesn't seem to work? I dont even get any error messages. The page loads but now it just doesn't show any body content.

    Am I missing something?

    Thanks

  • David Challener 44 posts 215 karma points c-trib
    Jan 27, 2019 @ 21:16
    David Challener
    0

    Hi Matt,

    Have you debugged this script at all? Can you try writing nodes.Count out to the page

    <pre>@nodes.Count()</pre>
    

    I think this would be my starting point to check you have something to paginate.

    Looking at your loop to write to the page, you have two foreach loops - 1 looping through the nodes, the other through the GuideLists' children again - I'm not sure this is what you're intending?

    Many thanks, David

  • David Challener 44 posts 215 karma points c-trib
    Feb 12, 2019 @ 23:56
    David Challener
    0

    Hi Matt,

    Did you get this resolved?

    Many thanks, David

Please Sign in or register to post replies

Write your reply to:

Draft