Copied to clipboard

Flag this post as spam?

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


  • praveen 113 posts 164 karma points
    Apr 20, 2018 @ 07:27
    praveen
    0

    Archetype - unable to get the fieldset property values

    Umbraco Version: 7.10.1 Archetype Version: 1.18.0

        public ActionResult RenderGallerySection()
        {
            List<GalleryItem> model = new List<GalleryItem>();
            IPublishedContent homePage = CurrentPage.AncestorOrSelf(1).DescendantsOrSelf().Where(x => x.DocumentTypeAlias == "home").FirstOrDefault();
            ArchetypeModel GalleryItems = homePage.GetPropertyValue<ArchetypeModel>("galleryItems"); 
    
            foreach (ArchetypeFieldsetModel fieldset in GalleryItems)
            {
                string imageCategory1 = fieldset.GetValue("name").ToString();
    
                //Get the URL of the Image
                var imageIdsmall = fieldset.GetValue<IPublishedContent>("shortImage");
                var mediaItemSmall = Umbraco.Media(imageIdsmall);
                string smallImgUrl = mediaItemSmall.Url;
    

    This line of code returns null: var imageIdsmall = fieldset.GetValue

    However when I add a watch to "fieldset" i can see the image URL

    Please help

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Apr 20, 2018 @ 08:39
    Alex Skrypnyk
    0

    Hi Praveen

    Use "Umbraco.AssignedContentItem" instead of CurrentPage. CurrentPage is dynamic type, which is not good and hard to debug

    IPublishedContent homePage = Umbraco.AssignedContentItem.AncestorOrSelf(1).DescendantsOrSelf().FirstOrDefault(x => x.DocumentTypeAlias == "home");
        ArchetypeModel GalleryItems = homePage.GetPropertyValue<ArchetypeModel>("galleryItems");
    
        foreach (ArchetypeFieldsetModel fieldset in GalleryItems)
        {
            string imageCategory1 = fieldset.GetValue("name").ToString();
    
            //Get the URL of the Image
            var imageIdsmall = fieldset.GetValue<IPublishedContent>("shortImage");
    }
    

    Thanks,

    Alex

  • praveen 113 posts 164 karma points
    Apr 20, 2018 @ 09:16
    praveen
    0

    Hi Alex

    Many thanks for the quick reply

    now the variable imageIdsmall has value

    var imageIdsmall = fieldset.GetValue

    However the next two lines have null value: var mediaItemSmall = Umbraco.Media(imageIdsmall); string smallImgUrl = mediaItemSmall.Url;

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Apr 20, 2018 @ 09:34
    Alex Skrypnyk
    0

    Praveen, what is output of imageIdsmall?

  • praveen 113 posts 164 karma points
    Apr 20, 2018 @ 09:40
    praveen
    0

    Hi Alex, Really appreciate your help

    below two lines resolved the issue, now I am able to get the Url //Get the URL of the Image string imageUrlSmall = fieldset.GetValue

    Can you please advise how to loop through the items to render the html:

    @inherits UmbracoViewPage<>

            foreach(@Model in GalleryItem)
            {
                @RenderGalleryItem(@Model[0])
            }
    
  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Apr 20, 2018 @ 10:03
    Alex Skrypnyk
    1

    Please, clarify what to render, and show all code

  • praveen 113 posts 164 karma points
    Apr 20, 2018 @ 10:10
    praveen
    0

    I want to render the below in foreach loop @RenderGalleryItem(@Model[0])

    enter image description here

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Apr 20, 2018 @ 10:43
    Alex Skrypnyk
    1

    Praveen, why do you pass List as a model? Just get list in the view

  • praveen 113 posts 164 karma points
    Apr 21, 2018 @ 10:00
    praveen
    0

    Sorry Alex, I don't understand, can you please elobrate Many thanks

  • praveen 113 posts 164 karma points
    Apr 23, 2018 @ 10:47
    praveen
    1

    Thanks Alex, resolved

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Apr 23, 2018 @ 10:47
    Alex Skrypnyk
    1

    You are welcome, Praveen, have a nice day!

  • 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" link below.

Please Sign in or register to post replies