1

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.

Alexander Ciesielski
  • 10,506
  • 5
  • 45
  • 66
Ritu Suman
  • 45
  • 7

2 Answers2

0

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>())
Santiago Morla
  • 377
  • 1
  • 7
  • The `CarouselViewModel` inherits from `Carousel_Folder` and extends it with the `[SitecoreChildren]` definition so the model is correct for getting children of the item. The code you added is not needed (or what I would recommended) : http://www.glass.lu/Blog/GettingChildItems – jammykam Jul 04 '16 at 21:38
0

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; }     

} 
Ayman Barhoum
  • 1,255
  • 1
  • 16
  • 31
  • 1
    I have a query, I just google this "IsLazy" and came to know that by default it's value is false. So, why do we need to write it here explicitly? It will be great, if you can help me to understand this. – Ritu Suman Jul 05 '16 at 04:22