Saving Mediaitem Saves Wrong Raw Value

12 views
Skip to first unread message

Bob Myers

unread,
Dec 18, 2014, 10:35:01 PM12/18/14
to glass...@googlegroups.com
We are creating a media item then saving it, the value of the reference field gets set as a GUID and not as a media item, i.e., <image mediaid="{655F48CF-5F8B-4232-98D6-0DA0E288F9C2}" />

We are referencing "virtual SitecoreMediaItem { get; set; }" and the SitecoreMediaItem has been posted here before:

//Template - /sitecore/templates/System/Media/Unversioned/Jpeg 
    [SitecoreType(AutoMap = true, TemplateId = "{DAF085E8-602E-43A6-8299-038FF171349F}")]
    public class SitecoreMediaItem
    {
        [SitecoreField("Mime Type")]
        public virtual string MimeType { get; set; }

        [SitecoreField("__Icon")]
        public virtual string Icon { get; set; }

        public virtual Guid Id { get; set; }
        public virtual string Name { get; set; }
        public virtual Stream Blob { get; set; }
        public virtual string Extension { get; set; }
        public virtual int Size { get; set; }

        //keep adding other field that you want to copy here
    }

This is frustrating, any ideas?

Michael Edwards

unread,
Dec 19, 2014, 2:27:03 AM12/19/14
to Bob Myers, glass...@googlegroups.com
Hi

You needs to use the Glass.Mapper.Sc.Fields.Image type and not you custom type if you are using and Image fields. For example my model might be:

public class MyModel{

    public virtual Guid Id{get;set;}
    public virtual Glass.Mapper.Sc.Fields Image {get;set; }
}



And my code will look like this:

MyModel model = service.GetItem<MyModel>("/sitecore/content/home");
Guid mediaId = "";  //this is retrieved from somewhere

model.Image = new Glass.Mapper.Sc.Fields.Image();
model.Image.MediaId = mediaId;

service.Save(model);

Let us know if you still have a problem.

Cheers

Mike









Mike Edwards
T: 07734 699316

Visit the website to find out about training, consultancy and development.


--
You received this message because you are subscribed to the Google Groups "Glass.Mapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glassmapper...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages