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?
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;}
}
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?
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?
thanks
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.
Regards,
Shaishav
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?
regards
is working on a reply...