Getting data from CurrentPage in Umbraco 7 and converting from obj to a type

44 Views Asked by At

In an Umbraco 7 controller I want to get carousel data from a CurrentPage and loop over it

var carousels = CurrentPage.GetProperty("carousels").Value;

carousels at this point is an object, but it should be a list of :

public class LearningPageCarousel
{
    public string Title { get; set; }
    public List<LearningLandingInfoCard> InfoCards = new List<LearningLandingInfoCard>();
}

I'm having trouble converting the object to the LearningPageCarousel type, is there a simple way to do this, or should I be getting the data from CurrentPage in a different way?

1

There are 1 best solutions below

0
DarkW1nter On BEST ANSWER

If anyone needs it here is the solution, I was casting incorrectly

    var carousels = CurrentPage.GetPropertyValue<IEnumerable<IPublishedContent>>("carousels");
foreach (var carousel in carousels)
            {
                    LearningPageCarousel learningPageCarousel = new LearningPageCarousel();
                    learningPageCarousel.Title = carousel.GetPropertyValue<string>("title");
        
        }