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
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...
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
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
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...
is working on a reply...