Copied to clipboard

Flag this post as spam?

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


  • nelsenlim 70 posts 71 karma points
    May 06, 2011 @ 06:45
    nelsenlim
    0

    DynamicMedia Check Type?

    Hi i have 2 questions first is

    1. How do i check for Media Type
    @Model.Media("media") i know that the syntax return the media, but how do i check for the type whether it is a folder or image?

    2. How do i get the first child of a folder
    var images = @Model.Media("media").Children;
    @foreach (var image in images)
            {

    above worked for looping the images in a folder but how do i get the first one without using looping i tried @Model.Media("media").Children.First() but calling First throws an error.

    The way i see it there is very limited functionality in DynamicMedia where DynamicNode seems to be much richer

  • Fengelz 106 posts 221 karma points
    Jun 10, 2011 @ 12:49
    Fengelz
    0

    1. You can retreive it like this: @image.ContentType.Alias.

    I think basically you can access the same properties you can on a umbraco.cms.businesslogic.media.Media object (not dead sure though)

    2. I'm not sure about this, but do write if you figure it out but I would fall back to the loop solution and exit after first loop.

    Best regards 

    - Sune

     

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Jun 10, 2011 @ 21:51
    Robert Foster
    0

    for number 2, you could try FirstOrDefault() instead of First().  That way if you have no children, it will just return null instead of throwing an exception...

Please Sign in or register to post replies

Write your reply to:

Draft