1
votes

Hi i am using glassmapper and i am trying to read all items in a multilist and populate.
My page has a a Navigation, Title and a multi list field where i can select the items . My problem is, while i am able to read the sub items (count is > 0) The property values are null. But Sitecore's basic Item properties are not null Fieldtype did not solve the problem These are my two Models

     public class Pagebase: ItemBase, INavigation
    {
        //Page Base

        public string PageTitle { get; set; }
        public string PageHeading { get; set; }

    //Navigation
        public string NavigationTitle { get; set; }
        public string NavigationDescription { get; set; }
    public IEnumerable<Pagebase> SubItems{ get; set; }
    }

[SitecoreType(TemplateId = "{7BC902B5-305B-484A-9AD9-6AAEBA48BDD7}", AutoMap = true)]
public interface INavigation 
{

    [SitecoreField("Navigation Title")]
        string NavigationTitle { get; set; }

        [SitecoreField("Navigation Description")]
        stringNavigationDescription { get; set; }

    [SitecoreField("Sub Items")]
        IEnumerable<Pagebase> SubItems{ get; set; }

}

My view is something like this

    @inherits Glass.Mapper.Sc.Web.Mvc.GlassView<xxx.Pagebase>

    <div class-"test"> 
@Model.NavigationTitle // This has value 
@Model.NavigationDescription // This has correct value
@Model.SubItems.Count // Show the correct number of Items selected in Multi list. 

// The multilist is again a Pagebase type. 
//When i do : 
    @foreach (var subItem in Model.SubItems)
                            {
    @subItem.NavigationTitle            //This is null
    @subItem.NavigationDescription  // This is null 
    @@subitem.Id / @subitem.Url / @subitem.Name /  // This is not null 
    }
    </div>   

What am i missing??

1
I think you need the SitecoreType attribute on your Pagebase class.DougCouto
Also, make sure you've published all of the templates and fields you created.DougCouto
@Barbosa if that is the case - i shouldnt be getting the values for even the base item. I am getting all the values for the base item perfectly fine. Model.NavigationTile works just. it is only for multilist that failsNight Monger
Anyone has any idea on this?Night Monger
Try setting your properties to virtual, e.g. public virtual string NavigationTitle { get; set; }jammykam

1 Answers

1
votes

In the implementation class of the interface you will need to mark all properties as virtual.

See also the documentation of glassmapper

And the rationale of using virtual properties with glassmapper.

So, your implementation class will look like this

public class Pagebase: ItemBase, INavigation
{
    //Page Base
    public virtual string PageTitle { get; set; }
    public virtual string PageHeading { get; set; }

   //Navigation
    public virtual string NavigationTitle { get; set; }
    public virtual string NavigationDescription { get; set; }
    public virtual IEnumerable<Pagebase> SubItems{ get; set; }
}