Copied to clipboard

Flag this post as spam?

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


  • pubudu 30 posts 133 karma points
    Aug 05, 2019 @ 05:52
    pubudu
    0

    Identify child page

    I need to add 2 sections on my web page. Like below

    Team Member: enter image description here Brands: enter image description here

    And I used to the new template to add those new items. enter image description here

    But finally all the new items I added, show in both places. enter image description here

    My Controller

    public ActionResult RenderAboutTeamMember()
        {List<MemberPreview> model = new List<MemberPreview>();
            IPublishedContent memberPage = CurrentPage.AncestorOrSelf(1).DescendantsOrSelf().Where(x => x.DocumentTypeAlias == "about").FirstOrDefault();
    
    
            foreach (IPublishedContent page in memberPage.Children)
            {
                int imageId2 = page.GetPropertyValue<int>("MemberImage");
                var mediaItem2 = Umbraco.Media(imageId2);
                model.Add(new MemberPreview(page.Name, 
                page.GetPropertyValue<string>("memberIntro"), 
                page.GetPropertyValue<string>("memberPost"), 
                page.GetPropertyValue<string>("linkedinLink"), 
                page.GetPropertyValue<string>("twitterLink"), 
                page.GetPropertyValue<string>("facebookLink"), 
                page.GetPropertyValue<string>("instaLink"),mediaItem2.Url,page.Url));
    
            }
    
            return PartialView("~/Views/Partials/Home/About/About_TeamMembers.cshtml", model);
        }
    
    
    
        public ActionResult RenderAboutBrands()
        {
            List<Brands> model = new List<Brands>();
            IPublishedContent homePage = 
            CurrentPage.AncestorOrSelf(1).DescendantsOrSelf().Where(x => 
             x.DocumentTypeAlias == "about").FirstOrDefault();
            ArchetypeModel Brands = 
            homePage.GetPropertyValue<ArchetypeModel>("brands");
    
            foreach (ArchetypeFieldsetModel fieldset in Brands)
            {
              var mediaItem = fieldset.GetValue<IPublishedContent>("imageLogo");
              string Bimage = mediaItem.Url;
              model.Add(new Brands(fieldset.GetValue<string>("brandName"), Bimage));
    
            }
            return PartialView("~/Views/Partials/Home/About/About_Brands.cshtml", model);
        }
    

    My Brand Model:

     public class BrandPreview
    {
        public string BrandName { get; set; }
        public string BrandImageUrl { get; set; }
        public string BrandLink { get; set; }
        public string BrandLinkUrl { get; set; }
    
        public BrandPreview(string brandname, string brandimageurl, string brandlinkurl,string brandlink)
        {
            BrandName = brandname;
            BrandImageUrl = brandimageurl;
            BrandLink = brandlink;
            BrandLinkUrl = brandlinkurl;
        }
    }
    

    My Member Model:

     public class MemberPreview
    {
        public string MemberName { get; set; }
        public string MemberPost { get; set; }
        public string MemberIntroduction { get; set; }
        public string MemberImageUrl { get; set; }
        public string MemberLinkUrl { get; set; }
    
        public string MemberLinkedin { get; set; }
        public string MemberTwitter { get; set; }
        public string MemberFacebook { get; set; }
        public string MemberInstagram { get; set; }
    
        public MemberPreview(string membername,string memberpost, string memberintro, string memberlinkedinLink, string membertwitterLink, string memberfaceBookLink, string memberinstragramLink, string memberimageurl, string memberlinkurl)
        {
            MemberName = membername;
            MemberPost = memberpost;
            MemberIntroduction = memberintro;
            MemberImageUrl = memberimageurl;
            MemberLinkUrl = memberlinkurl;
    
            MemberLinkedin = memberlinkedinLink;
            MemberTwitter = membertwitterLink;
            MemberFacebook = memberfaceBookLink;
            MemberInstagram = memberinstragramLink;
        }
    }
    

    I think problem is controller page code.in hear identify all the children page in current page. How can fix it???

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Aug 06, 2019 @ 15:16
    Marc Goodson
    100

    Hi pubudu

    I'm wondering if in your foreach loop you can filter out by 'document type alias'?

    eg

    foreach (IPublishedContent page in memberPage.Children.Where(f=>f.DocumentTypeAlias == "memberPost")) {
    

    this should mean that none of your brandPost items will be included in your first grouping.

    regards

    Marc

  • pubudu 30 posts 133 karma points
    Aug 08, 2019 @ 04:36
    pubudu
    0

    Thanks Marc. It's work. I'm a beginner to Umbraco and I had much time to waste find this. Thanks again. regards

Please Sign in or register to post replies

Write your reply to:

Draft