Bevin
Bevin

Reputation: 173

Sitecore Droplink set property not working

I have created the Glassmapper Models for all the items, I have a droplink in one of my Sitecore item. The Following is the model for the item with droplink field.

    [SitecoreClass]
   public class Field:BaseItem
    {
        [SitecoreField("Mapper Item")]
        public virtual LinkedItem MapperItem { get; set; }                
    }

Mapper Item field is a droplink field in sitecore, BaseItem class has all the sitecore base properties like:

        [SitecoreId]
    public virtual Guid Id { get; set; }

    [SitecoreInfo(SitecoreInfoType.Name)]
    public virtual string Name { get; set; }

    [SitecoreInfo(SitecoreInfoType.DisplayName)]
    public virtual string DisplayName { get; set; }

    [SitecoreInfo(SitecoreInfoType.Url)]
    public virtual string Url { get; set; }

    [SitecoreInfo(SitecoreInfoType.Path)]
    public virtual string Path { get; set; }

    [SitecoreInfo(SitecoreInfoType.ContentPath)]
    public virtual string ContentPath { get; set; }

    [SitecoreInfo(SitecoreInfoType.TemplateId)]
    public virtual Guid TemplateId { get; set; }

    [SitecoreInfo(SitecoreInfoType.TemplateName)]
    public virtual string TemplatedName { get; set; }

    [SitecoreField("__created")]
    public virtual DateTime Created { get; set; }

    [SitecoreField("__updated")]
    public virtual DateTime Updated { get; set; }

and LinkedItem has the following properties:

[SitecoreClass]
public class LinkedItem:BaseItem
{
    [SitecoreField("Field ID")]
    public virtual string FieldID { get; set; }
    [SitecoreField("Display Name")]
    public virtual string DisplayName { get; set; }
    [SitecoreField("Field Type")]
    public virtual string FieldType { get; set; }
}

I get the LinkedItem object in the MapperItem property when I am accessing the Field object, But if i try to set the MapperItem property its not saving it in the corresponding field ("Mapper Item" field), but I don't get any error.

I'm using the following code to set the droplink

fieldItem.MapperItem = ItemUtility.GetItem<LinkedItem>(new Guid("some valid guid available in the droplist source"));

Upvotes: 1

Views: 2208

Answers (1)

Jason Horne
Jason Horne

Reputation: 605

It looks like your on an old version of Glass mapper? Try adding the template reference like so:

[SitecoreClass(TemplateId = "{5281CBCF-1A2D-413A-B182-2854FC6B9176}")]

In the newest version it should be set as follows:

  • The namespace should be: using Glass.Mapper.Sc.Configuration.Attributes;

  • The classes should have an attribute: [SitecoreType(AutoMap = true)]

This link contains a good screen shot of the correct implmentation fo the above: http://www.glass.lu/en/Mapper/Sc/Tutorials/Tutorial11.aspx

Things to Check:

Upvotes: 1

Related Questions