Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1287 posts 2744 karma points
    Apr 12, 2014 @ 00:48
    Amir Khan
    0

    Check if Folder or Image is selected

    Is there a way to check if a folder or image has been selected by a media picker? It seems to return just the node id either way?

    Here's what I'm doing:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @if (Model.Content.HasValue("galleryImages"))
    {
    <ul>
    @{
    var galleryImagesList = Model.Content.GetPropertyValue<string>("galleryImages").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
    <h2>@galleryImagesList.ToString()</h2>
    var galleryImagesCollection = Umbraco.TypedMedia(galleryImagesList).Where(x => x != null);

    foreach (var galleryImage in galleryImagesCollection)
    {
    <li><img src="@galleryImage.Url" alt="@galleryImage.Name"></li>
    }
    }
    </ul>
    }
  • Amir Khan 1287 posts 2744 karma points
    Apr 12, 2014 @ 01:14
    Amir Khan
    0

    Well I've got that sorted. But now I'm running into a weird issue where if I don't include the line break before the "if" statment, I get a cs103 error?

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @if (Model.Content.HasValue("galleryImages"))
    {
    <ul>
    @{
    var galleryImagesList = Model.Content.GetPropertyValue<string>("galleryImages").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
    var galleryImagesCollection = Umbraco.TypedMedia(galleryImagesList).Where(x => x != null);

    foreach (var galleryImage in galleryImagesCollection)
    {
    string mediaType = @galleryImage.ContentType.Alias.ToString();
    <br/>
    if(@mediaType == "Image") {
    <li><img src="@galleryImage.Url" alt="@galleryImage.Name"></li>
    } else if (@mediaType == "Folder") {
    foreach (var folderItems in galleryImage.Children) {
    <li><img src="@folderItems.Url" alt="@folderItems.Name"></li>
    }
    }

    }
    }
    </ul>
    }

Please Sign in or register to post replies

Write your reply to:

Draft