Copied to clipboard

Flag this post as spam?

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


  • Peter Schermers 112 posts 134 karma points
    May 25, 2012 @ 12:18
    Peter Schermers
    1

    SImple Media Picker / Razor question

    I want to use a simple Media Picker with the name of "MediaPick" to load an image into a page using Razor.

    The only URL I retrieve from Razor is the URL (href="1219"). This of course doesn't show an image but an error.
    What change do I have make in my Razor script to get the FULL URL like 'media/photos/1219/image.jpg'?

    Below my code:

    @{
      var parent = @Model.AncestorOrSelf(3);
      var refNodes = parent.Children.Where("Visible");
      
      foreach (var item in refNodes){
        <div class="span3">
          <a class="group1" href="@item.afbeelding" title="@item.titel">
            <img src="@item.mediaPick" />
           </a>
        </div>
      }
    }


    I already found a lot of XSLT solutions, but I really just want to create the same thing in Razor.

    Thanks in advance!

  • Michael Latouche 502 posts 816 karma points c-trib
    May 25, 2012 @ 13:28
    Michael Latouche
    1

    Hi Peter,

    You get only the media item ID indeed. In order to gate the url, I think you need to use something like this:

    @Library.MediaById(item.mediaPick).NiceUrl

    You can find more help about this and other razor methods in the nice "razor cheat sheet" here : http://our.umbraco.org/projects/developer-tools/razor-dynamicnode-cheat-sheet

    Hope this helps.

    Cheers,

    Michael.

     

  • Peter Schermers 112 posts 134 karma points
    May 25, 2012 @ 13:41
    Peter Schermers
    0

    Hi Michael,

     

    Wow, that was quick! And exactly what I was looking for, thank you so much!

    I downloaded the razor cheatsheet earlier, but unfortunately my knowledge about razor isn't enough to understand everything in it ;-)

    Thanks again!

  • Michael Latouche 502 posts 816 karma points c-trib
    May 25, 2012 @ 14:55
    Michael Latouche
    0

    Hi Peter,

    You're very welcome :-)

    Cheers,

    Michael.

  • Fuji Kusaka 2203 posts 4220 karma points
    May 25, 2012 @ 15:42
    Fuji Kusaka
    1

    Hi Michael,


    One other way of doing this would be

    @item.Media("mediaPick","umbracoFile")


    I got  it working this way.

    //fuji

  • 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