In Umbraco 7 I create an image gallery (bootstrap carousel) from all images in a selected folder (mappe). Below is my code for V7, but it doesn't work i V 8:
@using System.Globalization
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
<!-- Wrapper for slides -->
<div class="carousel-inner">
@{
bool first = true;
var myMediaFolder = Umbraco.Media(@CurrentPage.Mappe);
foreach (var mediaItem in myMediaFolder.Children)
{
string aktiv = (first ? "active" : "");
<div class="carousel-item @aktiv">
<img src="@mediaItem.Url" alt="@mediaItem.Name" style="width: 100%">
</div>
first = false;
}
}
</div>
OK, now I have the folder (I can get it's name), but getting the children fails.
How do I cast it as a media-folder
Compiler Error Message: CS0446: Foreach cannot operate on a 'method group'. Did you intend to invoke the 'method group'?
Source Error:
Line 12: bool first = true;
Line 13: var myMediaFolder = Model.GalleriMappe;
Line 14: foreach (var mediaItem in myMediaFolder.Children)
Compiler Error Message: CS1929: 'IEnumerable<IPublishedContent>' does not contain a definition for 'Children' and the best extension method overload 'PublishedContentExtensions.Children(IPublishedContent, string)' requires a receiver of type 'IPublishedContent'
Source Error:
Line 12: bool first = true;
Line 13: var myMediaFolder = Model.GalleriMappe;
Line 14: foreach (var mediaItem in myMediaFolder.Children())
Get All Images from Media Folder Problem
In Umbraco 7 I create an image gallery (bootstrap carousel) from all images in a selected folder (mappe). Below is my code for V7, but it doesn't work i V 8:
Hi Ole
UmbracoTemplatePage and CurrentPage have been removed from Umbraco 8.
In stead you should use UmbracoViewPage and strongly typed access to your properties. If you use modelsbuilder, that would be Model.Mappe.
OK, now I have the folder (I can get it's name), but getting the children fails. How do I cast it as a media-folder
Try this
Source Error:
Line 12: bool first = true;
Line 13: var myMediaFolder = Model.GalleriMappe; Line 14: foreach (var mediaItem in myMediaFolder.Children())
If Model.GalleriMappe is of IEnumerable<IPublishedContent> you should probably not call children since that model already contains a collection. Try:
Regards, Magnus
That doesn't throw any errors, but gives me one elemen with the name of the chosen folder = Forside:
Thanks a lot guys. That was the trick. Have a very nice evening :)
is working on a reply...