Copied to clipboard

Flag this post as spam?

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


  • Sowndar M 38 posts 109 karma points
    Apr 30, 2019 @ 11:57
    Sowndar M
    0

    Load More issue

    I have 7 post in the list. it has to show each 3 post when I click the Loadmore. Load More work until reach the 6 post then after it won't show the remaining one post and freeze after reach the 6 posts

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @using ContentModels = Umbraco.Web.PublishedModels;
    @{
        Layout = "master.cshtml";
    
        var site = Model;
        var listing = Model.Descendants("listing").Where(x => x.IsVisible()).OrderByDescending(x => x.CreateDate);
    
        var skip = 3;
    
        if (!string.IsNullOrEmpty(Request.QueryString["num_of_listing"]))
        {
            skip = Convert.ToInt32(Request.QueryString["num_of_listing"]);
        }
    
    
        var stop = listing.Count();
    
    }
    
    @Html.Partial("~/Views/Partials/Shared/Banner.cshtml")
    
    @if (listing.Any())
    {
    
    
        <section class="listing padding-top-100 padding-bottom-100">
            <div class="container">
                <div class="row">
                    <div class="col-12 top-head">
                        @if (site.Value("listingMainTitle") != null)
                        {
                            <h2 class="text-center mb-5 title-underline">@site.Value("listingMainTitle")</h2>
                        }
    
                        @if (site.Value("listingMainContent") != null)
                        {
                            <p class="width-half text-center mx-auto">@site.Value("listingMainContent")</p>
                        }
    
    
                    </div>
                    @foreach (var item in listing.Take(skip))
                    {
    
                        var listingImage = item.Value<IPublishedContent>("bannerImage");
                        var bannerTitle = item.Value<IPublishedContent>("bannerTitle");
                        <div class="col-md-4 mb-4  text-center">
                            <div class="listing-item">
                                @if (listingImage != null)
                                {
                                    <img class="img-fluid mb-4" src="@listingImage.Url" alt="@item.Name" />
                                }
                                <div class="listing-item-content">
                                    @if (bannerTitle != null)
                                    {
                                        <a href="@item.Url"><h5>@bannerTitle</h5></a>
    
                                    }
                                    else
                                    {
    
                                        <a href="@item.Url"><h5>@item.Name</h5></a>
                                    }
    
                                    @(Html.Raw(item.Value("bannerContent").ToString().Truncate(100)))
                                </div>
                            </div>
    
                        </div>
                    }
    
                    @if (skip > stop)
                    {
    
                        <div class="post-bottom mx-auto"><h5 class="text-center">You have reached the bottom...!</h5></div>
    
                    }
                    else
                    {
    
                        <div class="col-md-12 text-center mt-5">
                            <button class="btn load-more">Load More </button>
                        </div>
    
                    }
                </div>
            </div>
    
        </section>
    
    
    <script>
    
            var skip = @skip;
            var count = skip;
            $(".load-more").click(function () {
    
                debugger;
                skip = skip + count;
    
                var stop = @listing.Count();
    
                $.ajax({
                            url: '@Model.Url',
                            Type: 'get',
                            data: {
                                num_of_listing: skip,
    
    
                            },
                            success: function (html) {
                                var div = $('.listing .container', $(html));
                                $('.listing').html(div);
                            }
                        });
            });
        </script>
    
    
    }
    
  • Rhys Hamilton 140 posts 940 karma points
    Apr 30, 2019 @ 13:28
    Rhys Hamilton
    1

    By the looks of things, the value in your num_of_listing appears to be 6 - which matches the number of items that you're successfully returning.

    I'm assuming the num_of_listing refers to the number of records returned? If you change this value to 10, I'd expect your "load more" function to work for 10 items.

    If this is the case, then perhaps your num_of_listing should read num_of_listing: stop instead of num_of_listing: skip - since stop appears to get the total number of items whereas skip does not.

    Hopefully this helps!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" button below.

    Continue discussion

Please Sign in or register to post replies