Copied to clipboard

Flag this post as spam?

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


  • Meni 243 posts 479 karma points
    Sep 22, 2022 @ 22:33
    Meni
    0

    Image not display after change (Obsolete) Media Picker to Umbraco.MemberPicker2

    Hi, I changed the Media Picker data type from (Obsolete) Media Picker to Umbraco.MemberPicker2 and now images no longer display on my website.

    This is my code to display image:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
    if(CurrentPage.HasValue("articleImg")){      
        string w = (string)Umbraco.Media(CurrentPage.articleImg).umbracoWidth;  
        string h = (string)Umbraco.Media(CurrentPage.articleImg).umbracoHeight;
    
        int imgWidth = w.AsInt();
    
        if (imgWidth > 1500) {
            <div class="col-xl-12" class="news-page-img-container">
                <img src="@Umbraco.Media(CurrentPage.articleImg).Url" alt="@CurrentPage.photoAlt" class="news-img" />
            </div>  
        }
        else {
                <div class="col-xl-2 col-lg-2 col-md-2">
                </div>
                <div class="col-xl-8 col-lg-8 col-md-8">
                    <img src="@Umbraco.Media(CurrentPage.articleImg).Url" alt="@CurrentPage.photoAlt" class="img-fluid" />
                </div>
                <div class="col-xl-2 col-lg-2 col-md-2">
                </div> 
            }       
    }
    

    Any idea why images no longer display? (even after pick them again)

    Thanks

  • Meni 243 posts 479 karma points
    Sep 23, 2022 @ 05:41
    Meni
    100

    Ok, I figured out and resolved the issue. I only had to add to each @Umbraco.Media .ToString()

    @Umbraco.Media(CurrentPage.articleImg.ToString()).Url
    

    I guess is because the new media picker 2 uses udi which is string and not int ?

    Anyway it works for me

    Thanks also for this answer:

    https://stackoverflow.com/questions/37941476/umbraco-how-to-display-an-image-from-a-media-picker-in-the-src-of-an-img-tag

Please Sign in or register to post replies

Write your reply to:

Draft