Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    May 02, 2012 @ 15:59
    Fuji Kusaka
    0

    Media Picker with Razor not displaying Images

    Hi all,

    Can someone explain why am not getting an display when using Media Picker with alias "Slider" in razor.

    @using umbraco.MacroEngines
    @
         var  chosenMedia  =  Model.MediaById("slider");
         if  (chosenMedia.NodeTypeAlias  ==  "Folder")
         {
             foreach  (var  img  in  chosenMedia.Children)
             {
                 if  (img.NodeTypeAlias  ==  "Image")
                 {
                             
                     <img  src="@img.umbracoFile"/>
                
                 }
             }
         
    }
  • Tom Fulton 2030 posts 4998 karma points c-trib
    May 02, 2012 @ 16:09
    Tom Fulton
    0

    Hi Fuji,

    Model.MediaById expects an integer representing the ID of the media, not a nodeTypeAlias.

    Assuming your document has a media picker with the alias of slider that selects a folder?  You could try:

    var chosenMedia = Model.MediaById(Model.slider);

    -Tom

  • Fuji Kusaka 2203 posts 4220 karma points
    May 02, 2012 @ 16:18
    Fuji Kusaka
    0

    Hi Tom, 

    I did try this out as well but no output. Am using a Media Picker with Alias "Slider".

     var  chosenMedia  =  Model.MediaById(Model.slider);

         if  (chosenMedia.NodeTypeAlias  ==  "Folder")
         {
             foreach  (var  img  in  chosenMedia.Children)
             {
                 if  (img.NodeTypeAlias  ==  "Image")
                 {
                             
                     <img  src="@img.UmbracoFile" alt="@img.Name"/>
                
                 }
             }
         
  • Tom Fulton 2030 posts 4998 karma points c-trib
    May 02, 2012 @ 16:43
    Tom Fulton
    0

    Seems to work fine from here, you sure you're using the right aliases, have the right folder selected etc?  Maybe try setting some breakpoints if using VS or otherwise output some info to make sure your checks are passing..

    <p>slider:  @Model.slider</p>
    <p>chosenMedia.NodeTypeAlias:  @chosenMedia.NodeTypeAlias</p>
    <p>img.NodeTypeAlias:  @img.NodeTypeAlias</p>

    etc

    -Tom

  • Fuji Kusaka 2203 posts 4220 karma points
    May 02, 2012 @ 20:00
    Fuji Kusaka
    0

    Yes i works Tom, Looks like at some point the "Save and Publish" wasnt doing anything.

     

    //fuji

     

     

Please Sign in or register to post replies

Write your reply to:

Draft