Copied to clipboard

Flag this post as spam?

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

  • Damion 85 posts 319 karma points
    Aug 21, 2019 @ 11:02

    dynamically build a dropdown in a custom dash based on folders under 'Media'

    I have a custom dashboard (.html file) where I will let users upload media items.

    The upload works fine but I need to allow them to choose the parent folder they are uploading to, and as the id's could change if the folders change, I need to build up a dropdown dynamically.

    As the dash is html and not cshtml, is there a way to get access to the folders under Media, and do a foreach to build a list?

    If this is possible if anyone could point me to an example that would be great, if not then what's the alternative?


  • Shaishav Karnani from 346 posts 1623 karma points
    Aug 21, 2019 @ 11:17
    Shaishav Karnani from

    Hi Damion,

    You can try calling API and receive JSON from back-end. Below code will assist for Media Folders. Then you can use JQuery to populate dropdown.

    Hope that helps. Please let me know your views.

    public class MediaController : UmbracoApiController
        public IEnumerable<MediaItem> GetAllMediaFolder()
    var allFolders = Umbraco.TypedMediaAtRoot().DescendantsOrSelf("folder");
    return allFolders.Select(x=>new MediaItem() {Id = x.Id, Name = x.Name});        
    public class MediaItem {
        public int Id {set; get;}
        public string Name {set; get;}



  • Damion 85 posts 319 karma points
    Aug 21, 2019 @ 12:45

    Hi Shaishav,

    thanks for this I think it should give me what I want. Given that I'm doing this in a dashboard, how would that controller be fired, should I have a dashboard controller?


Please Sign in or register to post replies

Write your reply to: