1
votes

We are facing issue in Glass mapper 4.0 where it does not load item children.

Here is our controller class , It is inheriting from GlassController:

public class CarouselController : GlassController
{
    public ActionResult GetCarousel()
    {
        Model = this.GetDataSourceItem<CarouselViewModel>();
        return View(Model);
    }
}

And here is our View Model:

public class CarouselViewModel:Carousel_Folder
{      
    [SitecoreChildren]
    public virtual IEnumerable<Carousel> Carousels { get; set; }
}

we get only the parent node information not the childeren (carousels) in the result

Here is the result we get:

[Result Image][1]

Also, following classes were generated with TDS:

[SitecoreType(TemplateId = ICarousel_FolderConstants.TemplateIdString )] //, Cachable = true
public partial interface ICarousel_Folder : IGlassBase
{}

Carousel template is inheriting from two templates content base and image base.

2
Are you sure the results are empty? Did you try to expand the results view? - Gatogordo
Do you understand the difference between IEnumerable<> and List<>? - Mark Cassidy

2 Answers

0
votes

It seems that Carousels property is not par of the Carousel_Folder template, that's why your Interface/Class doesn't have something like:

[SitecoreType(TemplateId=ICarousel_FolderConstants.TemplateIdString)]
public partial class Carousel_Folder  : GlassBase, ICarousel_Folder 
{
    [SitecoreField(ICarouselConstants.CarouselsFieldName)]
    public virtual IEnumerable<Carousel> Carousels {get; set;}
}

In this case you will need to get the Parent item and get the children manually, i.e.:

var children = parentItem.Children.Select(x => x.GlassCast<Carousel>())
0
votes

I had this issue before, for me i added [SitecoreChildren(IsLazy = false)] to my model and it works fine, in your case it should be like this :

public class CarouselViewModel:Carousel_Folder
{

    [SitecoreChildren(IsLazy = false)]
    public virtual IEnumerable<Carousel> Carousels { get; set; }     

}