MediaLibraryPicker cannot access media part from view

Topics: Customizing Orchard
Feb 21, 2014 at 7:01 AM
I'm having an issue with MediaLibraryPicker field.

I'm trying to create a custom carousel using projection page.
  • I have create a new content type called Carousel and added 3 text fields and 2 media library picker fields.
  • I have created a query also to pick all carousel types
Now I want to override the Content-Carousel.Summary.cshtm view to render in a custom way the fields. I can access with no issue the text fields but the MediaPart for the images fields are empty. If I put in this view Display(Model.Content) it displays all the fields including the images as I have updated the also to include the medialibrarypicker in summary detail.

The only issue is that I cannot access the picture url using Model.ContentItem.Carousel.Picture1.MediaPart[0].MediaUrl as MediaPart is empty.

Please advise,
Feb 21, 2014 at 5:50 PM
Anyone any help with the above. It's very frustrating that such an CMS does'n have a straight forward way to handle a simple images. I'm seriously thinking of choosing a different cms.
Feb 21, 2014 at 9:27 PM
There isn't really enough information to troubleshoot here.

I'd recommend using Shape Tracing to look at the model (if you aren't already) to find the exact dot path to your URL. Your path doesn't look right.

Check out this snippet from the Media Picker Library summary views. It might point you in the right direction.
@using Orchard.ContentManagement
@using Orchard.MediaLibrary.Models
    ImagePart imagePart = Model.ContentPart;
    var mediaPart = ((ContentItem)Model.ContentItem).As<MediaPart>();

@* Use a 200x200 profile in order to reuse the general thumbnail *@
<a href="@Url.Content(mediaPart.MediaUrl)">
Feb 23, 2014 at 11:26 AM
Thanks for the reply.

I have used a text field instead of the media library picker one and update manually the path there. I'll be using this till I'll find a better solution.