Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gert 81 posts 288 karma points
    Nov 07, 2016 @ 10:05
    Gert
    0

    Problem fetching image in view in Umbraco 7.5

    This code worked perfectly fine in Umbraco 7.3.

    var image = Umbraco.TypedMedia( ( int )CurrentPage.BannerBackgroundImage.Id );
    

    BannerBackgroundImage is of data type Media Picker.

    In a clean Umbraco 7.5.4 install I get the following Exception (RuntimeBinderException).

    'Umbraco.Web.Models.DynamicPublishedContentList' does not contain a definition for 'Id'

    Umbraco.ModelsBuilder.Enable is set to false in the web.config.

    How should I solve this?

    Thanks! Gert.

  • carlu 42 posts 131 karma points
    Nov 08, 2016 @ 08:43
    carlu
    0

    Hi Gert,please try it

    @if (CurrentPage.HasValue("BannerBackgroundImage")) {

                          @{var dynamicMediaItem = Umbraco.Media(CurrentPage.BannerBackgroundImage);
                         <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name" style="width:100%; " />
                     }
    
                     }
    
  • Gert 81 posts 288 karma points
    Nov 08, 2016 @ 10:22
    Gert
    0

    Hi Carlu,

    This didn't help, but the following did

     IPublishedContent image = Umbraco.TypedMedia( CurrentPage.BannerBackgroundImage.First().Id );
    

    So it's a mystery to me why the Media Picker suddenly returns a collection in Umbraco 7.5? I also had to explicitely define the type IPublishedContent because when I used the var keyword, then the type was not correctly inferred and the call:

    imageUrl = image.GetCropUrl( 800, 600 );
    

    did not work. Image then turnes out to be of type dynamic and the call GetCropUrl() throws an exception: 'Umbraco.Web.Models.PublishedContentWithKeyBase' does not contain a definition for 'GetCropUrl'

    What is also strange is that the call image.GetPropertyValue( "umbracoWidth" ); returns a string now instead of an integer. Any idea why this is changed in Umbraco 7.5?

    Regards, Gert.

  • Gert 81 posts 288 karma points
    Nov 08, 2016 @ 10:51
    Gert
    1

    Hi,

    I found a solution for the media picker returning a collection. When I go the the Media Picker data type and I check the option, "Pick multiple items", save it, uncheck it and save it again then the media picker property won't return a collection but instead a single (dynamic) Umbraco.Web.Models.PublishedContentWithKeyBase which should be casted to IPublisheContent.

    Cheers, Gert.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies