Copied to clipboard

Flag this post as spam?

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


  • Noor Alam 26 posts 97 karma points
    Aug 30, 2019 @ 04:07
    Noor Alam
    0

    Needs to implement pagination in umbraco cms v8 .. Please suggest me.

    Needs to implement pagination in umbraco cms v8 .. Please suggest me.

  • Shaishav Karnani from digitallymedia.com 349 posts 1631 karma points
    Aug 30, 2019 @ 04:47
    Shaishav Karnani from digitallymedia.com
    0

    Hi Noor,

    Please can you review the logic on this article related to pagination. This also applies to Umbraco 8 although some syntax could slightly change.

    https://stackoverflow.com/questions/24906410/umbraco-pagination

    Please review and share your views.

    Regards, Shaishav

  • Noor Alam 26 posts 97 karma points
    Aug 30, 2019 @ 04:49
    Noor Alam
    0

    Sure Shaishav ... I am just trying to implement and let you know Thanks

  • Noor Alam 26 posts 97 karma points
    Aug 30, 2019 @ 06:46
    Noor Alam
    0

    @inherits Umbraco.Web.Mvc.UmbracoViewPage

    <section id="one">
    
        @{
            var pageSize = 8;
            if (Model.Content.HasValue("numberOfItemsPerPage"))
            {
                pageSize = Model.Content.GetPropertyValue<int>("numberOfItemsPerPage");
            }
    
            var page = 1; int.TryParse(Request.QueryString["page"], out page);
            var items = Umbraco.TypedContent(Model.Content.Id).Children.Where(x => x.DocumentTypeAlias == "exampleAlias" && x.IsVisible());
            var totalPages = (int)Math.Ceiling((double)items.Count() / (double)pageSize);
    
            if (page > totalPages)
            {
                page = totalPages;
            }
            else if (page < 1)
            {
                page = 1;
            }
    
            foreach (var item in items.Skip((page - 1) * pageSize).Take(pageSize).OrderBy("createDate descending"))
            {
    
                <div class="example-div">
                            <h3><a href="@item.GetPropertyValue("Url")">@item.GetPropertyValue("Name")</a></h3>
                </div>
            }
    
            if (totalPages > 1)
            {
                <div class="pagination">
                    <ul>
                        @if (page > 1)
                        {
                            <li><a href="[email protected](page-1)">Prev</a></li>
                        }
                        @for (int p = 1; p < totalPages + 1; p++)
                        {
                            <li class="@(p == page ? "active" : string.Empty)">
                                <a href="[email protected]">@p</a>
                            </li>
                        }
                        @if (page < totalPages)
                        {
                            <li><a href="[email protected](page+1)">Next</a></li>
                        }
                    </ul>
                </div>
            }
        }
    </section>
    

    After using shared code getting attached error. Please suggest. enter image description here

  • Noor Alam 26 posts 97 karma points
    Aug 30, 2019 @ 07:03
    Noor Alam
    0

    Since i am inherits **

    Umbraco.Web.Mvc.UmbracoViewPage ContentModels.News

    ** and using ContentModels = Umbraco.Web.PublishedModels

    Please suggest. As i have added multiple news with parent and child pages with news and news details. and in user interface i am trying to show in using partial view.

    see screen shot.

    enter image description here

  • Shaishav Karnani from digitallymedia.com 349 posts 1631 karma points
    Aug 30, 2019 @ 07:14
    Shaishav Karnani from digitallymedia.com
    0

    Hi Noor,

    Please can you check if you need Model.Content.HasValue or Model.HasValue. I think you need later.

    Regards,

    Shaishav

  • Noor Alam 26 posts 97 karma points
    Aug 30, 2019 @ 10:04
    Noor Alam
    0

    Now i am getting below error enter image description here

  • Steve Megson 150 posts 942 karma points MVP c-trib
    Aug 30, 2019 @ 13:52
    Steve Megson
    0

    .GetPropertyValue<T>(alias) has been replaced by .Value<T>(alias) in version 8.

  • Shaishav Karnani from digitallymedia.com 349 posts 1631 karma points
    Aug 30, 2019 @ 13:27
    Shaishav Karnani from digitallymedia.com
    0

    You can add following namespaces to your web.config of views folder. This will allow you to get access to above methods.

            <add namespace="Umbraco.Web" />
            <add namespace="Umbraco.Core" />
            <add namespace="Umbraco.Core.Models" />
            <add namespace="Umbraco.Web.Mvc" />
            <add namespace="umbraco" />
            <add namespace="Examine" />
            <add namespace="Umbraco.Web.PublishedContentModels" />
    

    Cheers,

    Shaishav

  • Noor Alam 26 posts 97 karma points
    Aug 30, 2019 @ 19:26
    Noor Alam
    0

    As per your suggestion i have changed the code and i am not getting error. But when i am running page not getting output even pagination :( Please check following code

    @inherits Umbraco.Web.Mvc.UmbracoViewPage

    @{ Layout = "webbaseTempate.cshtml"; }

    @{
        var pageSize = 2;
        if (Model.HasValue("numberOfItemsPerPage"))
        {
            pageSize = Model.Value<int>("numberOfItemsPerPage");
        }
    
        var page = 1; int.TryParse(Request.QueryString["page"], out page);
        var items = Umbraco.Content(Model.Id).Children.Where(x => x.ContentType.Alias == "exampleAlias" && x.IsVisible());
        var totalPages = (int)Math.Ceiling((double)items.Count() / (double)pageSize);
    
        if (page > totalPages)
        {
            page = totalPages;
        }
        else if (page < 1)
        {
            page = 1;
        }
    
        foreach (var item in items.Skip((page - 1) * pageSize).Take(pageSize).OrderBy(x => x.CreateDate).ToList())
        {
    
            <div class="example-div">
                <h3><a href="@item.Value("Url")">@item.Value("Name")</a></h3>
            </div>
        }
    
        if (totalPages > 1)
        {
            <div class="pagination">
                <ul>
                    @if (page > 1)
                    {
                        <li><a href="[email protected](page-1)">Prev</a></li>
                    }
                    @for (int p = 1; p < totalPages + 1; p++)
                    {
                        <li class="@(p == page ? "active" : string.Empty)">
                            <a href="[email protected]">@p</a>
                        </li>
                    }
                    @if (page < totalPages)
                    {
                        <li><a href="[email protected](page+1)">Next</a></li>
                    }
                </ul>
            </div>
        }
    }
    

    Please suggest. Very exciting to see the pagination

  • Steve Megson 150 posts 942 karma points MVP c-trib
    Aug 30, 2019 @ 19:48
    Steve Megson
    0

    I assume that your site doesn't have a document type called exampleAlias, so this line doesn't match any items:

     var items = Umbraco.Content(Model.Id).Children.Where(x => x.ContentType.Alias == "exampleAlias" && x.IsVisible());
    

    If you want a paged list of all children of any document type, this should do the job:

     var items = Umbraco.Content(Model.Id).Children;
    
  • Noor Alam 26 posts 97 karma points
    Aug 30, 2019 @ 20:06
    Noor Alam
    0

    Thanks Steve............ Its working now. :)

  • Amir Khan 1209 posts 2581 karma points
    Aug 30, 2019 @ 20:24
    Amir Khan
    0

    Small thing, you might want to keep .Where(x => x.IsVisible()); or .Where("Visible") to skip nodes where umbracoNaviHide is checked.

Please Sign in or register to post replies

Write your reply to:

Draft