I have class CarouselViewModel as below

    public class CarouselViewModel
        [SitecoreField(FieldName = "Selected Items")]
        public IEnumerable<CarouselSlides> CarouselSlides { get; set; }

The CarouselViewModel containes carouselSlides

    public class CarouselSlides
           [SitecoreField(FieldType = SitecoreFieldType.Image, FieldName = "Image")]
        public virtual Image Image { get; set; }


Using glass mapper I am getting count as 3 in CarouselViewModel but the imagefield in individual carouselSlides is always coming as null. Is there something i am doing wrong while mapping the field. The field contains value and while using direct sitecore fields I am able to populate the model.

  • I don't know why this question was put on hold, I've seen several people have this issue before and as such may help others in the future. – jammykam Aug 19 '17 at 17:20
  • Forgetting to inherit from GlassBase is a simple error; the resolution to which has nothing to do with the question title or image fields for that matter. Question and answer would need a lot of rework to be of any use for the records - e.g. something that would be useful and show up in a search engine search and provide an answer. – Mark Cassidy Aug 19 '17 at 19:31
  • Also; holding and ultimately closing a question doesn't mean it's going away. Just means that OP had a problem and in this case OP found his own solution. No additional answers need to be added - and none would be useful anyway, given the misleading question and title. – Mark Cassidy Aug 19 '17 at 19:35
  • 1
    The ultimate issue was not forgetting to inherit from Glassbase, it was not having a property for [SitecoreId] declared (which is included Glassbase). Unfortunately, since the question was put on hold, it means it could not be added as an answer. – jammykam Aug 21 '17 at 0:34

Inheriting the classes from GlassBase solved the issue

public class GlassBase
    string Name { get; set; }
    string Template { get; set; }
  • 1
    The Model should have worked as in your original code, but for Experience Editor mode you need to ensure a [SitecoreId] public virtual Guid Id { get; set; } is declared. This was more likely the issue (and what inheriting from GlassBase resolved - glass.lu/Mapper/Sc/Tutorials/Tutorial5 – jammykam Aug 19 '17 at 17:28
  • Thanks jammykam, but the code was not working when it was not inherited from glassbase. – rdhaundiyal Aug 20 '17 at 15:12
  • Yes, I understand that. But I'm telling you thr reason why. It's not necessary to inherit from Glassbase. Most likely you are using Codegen, Glassbase is not a requirement for those mnaully creating their models. – jammykam Aug 20 '17 at 15:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.