Copied to clipboard

Flag this post as spam?

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


  • namhoang1594 8 posts 78 karma points
    Jul 23, 2021 @ 17:21
    namhoang1594
    0

    How to get children items of children?

    Hi guys, I wanna get children items in Group Tours, i have tried so many ways but still not showing children items. Please help me, teach me how to do it :( enter image description here

    and here is the code i try, but it's wrong

        @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.GroupTours>
    @using ContentModels = Umbraco.Web.PublishedModels;
    @{
        Layout = "master.cshtml";
        var home = (Home)Model.Root();
        var numberOfGroupTours = (int)Model.HowManyGroupToursShouldBeShown;
        var newsTours = Model.Children.OrderByDescending(c => c.CreateDate).ToList();
        var pageCount = (int)Math.Ceiling((double)newsTours.Count / numberOfGroupTours);
        //gets the page from the querystring and sets it to one if it is out of range
        var page = 1;
        if (!string.IsNullOrEmpty(Request.QueryString["page"]))
        {
            int.TryParse(Request.QueryString["page"], out page);
            if (page <= 0 || page > pageCount)
            {
                page = 1;
            }
        }
        //Gets the tours for the current page
        var pagedNewsTours = newsTours.Skip((page - 1) * numberOfGroupTours).Take(numberOfGroupTours).ToList();
    }
    

    and

     @{
                        if (Model.Children != null)
                        {
                            foreach (GroupTours gtours in pagedNewsTours)
                            {
                                foreach (ToursItem toursItem in pagedNewsTours)
                                {
                                <div class="item_tours">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <h2 class="name_tours">
                                                <a href="@toursItem.Url()">
                                                    @toursItem.PageTitle
                                                </a>
                                            </h2>
                                            <div class="price">@toursItem.Price</div>
                                        </div>
                                    </div>
                                    <div class="float">
                                        <a href="@toursItem.Url()">
                                            <img class="img_tours" src="@toursItem.ThumbnailImage.LocalCrops" alt="">
                                        </a>
                                        <div class="summary_tours">
                                            @toursItem.ShortContent
                                        </div>
                                    </div>
                                </div>
                                    }
                                }
                            }
                        }
    

    Help me. Thank you so much guys :(

  • Amir Khan 1282 posts 2739 karma points
    Jul 23, 2021 @ 18:07
    Amir Khan
    0

    I think this line

    foreach (ToursItem toursItem in pagedNewsTours)
    

    Should be

    foreach (ToursItem toursItem in gtours)
    

    Currently you're just looping through the original loop again.

Please Sign in or register to post replies

Write your reply to:

Draft