Copied to clipboard

Flag this post as spam?

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


  • Michele Benolli 31 posts 149 karma points
    Oct 04, 2022 @ 16:33
    Michele Benolli
    0

    Error reading content properties in RenderMvcController

    I have a problem accessing the content properties in a RenderMvcController. I have a page with some children and I want to access a certain property of each child page. The problem is that the property value of the first child seems to be propagated to the siblings. Each child page has a different image but the value I read in productPage.Image is always the same. In addition, if I inspect the value of a specific child image when debugging in Visual Studio, productPage.Image is set to the value of the first inspected child! Do you know why does this happen?

    public class ProductPageController : Umbraco.Web.Mvc.RenderMvcController
    {
        public override ActionResult Index(ContentModel model)
        {
            var children = contentModel.Content.Children;
            foreach (var child in children)
            {
                if (child is ProductPage productPage)
                {
                    // Access the product image 
                    var image = productPage.Image;
    
                    // Do some operations, etc...
                }
            }
        }
    }
    
  • 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