Copied to clipboard

Flag this post as spam?

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


  • Lars 66 posts 136 karma points
    Dec 20, 2015 @ 21:17
    Lars
    0

    Getting content from Media Picker strongly typed

    Hi. I am using Umbraco 7 and I want to get the content from a Media Picker field in a razor view.

    I have only one field so I don't need an array. I have the "official" umbraco example for getting the value of the Media Picker in strongly typed razor:

    @if (Model.Content.HasValue("caseStudyImages")) { var caseStudyImagesList = Model.Content.GetPropertyValue

    foreach (var caseStudyImage in caseStudyImagesCollection)
        {      
            <img src="@caseStudyImage.Url" style="width:300px;height:300px" />      
        }                                                                
    

    }

    I want to get the content but without an array since I have only one value. Does anyone know how to do this?

    //Lars

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 20, 2015 @ 21:30
    Jeavon Leopold
    101

    Hi Lars,

    Something like this

    @if (Model.Content.HasValue("caseStudyImages")) { 
    var caseStudyImageId = Model.Content.GetPropertyValue<int>("caseStudyImages");
    var caseStudyImage = Umbraco.TypedMedia(caseStudyImageId);
            <img src="@caseStudyImage.Url" style="width:300px;height:300px" />                                                            
    }
    

    Jeavon

  • Lars 66 posts 136 karma points
    Dec 21, 2015 @ 07:25
    Lars
    0

    Hi Jeavon

    Thank you for a quick and even right answer and have a nice day. It *&ยค%&#/" works :-)

  • 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