I've just updated to 8.1.5 and am having the following issue.
Old code in a controller:
var imagePicker = campingPage.Value<IEnumerable<IPublishedContent>>("images");
var imageUrl = "/placeholder.jpg";
//Check if folder is selected
if (imagePicker.Any())
{
//Select the folder
var imageNode = imagePicker.First();
//Check if the folder has any children(images)
if (imageNode.Children.Any())
{
//Get the first image
var image = imageNode.Children().First();
Only this has stopped working. I've been trying for a few hours now and am quite stuck. The mediafolder always has 'null' children.
var imagePicker = campingPage.Value<IPublishedContent>("images");
var imagePickertest = campingPage.Images;
var mediaId = imagePicker.Id;
var mediaFolder = Umbraco.Content(mediaId);
All of these(except the MediaId) result in a null value when adding .Children().. However, it ofcourse DOES have children.
Fun fact when having similar code on a normal TemplatePage, it DOES work
@helper RenderItem(CampingPage camping)
{
var imagePicker = camping.Images;
var imageUrl = "/placeholder.jpg";
if (imagePicker != null)
{
if (imagePicker.Children().Any())
{
var image = imagePicker.Children().First();
Is your Media Picker configured to pick multiple items? or a single folder?
I wonder if in the controller the PropertyValueConverter is being clever and detecting that only a single media item is pickable and therefore the item is convertable to an IPublishedContent item rather than an IEnumerable
eg try:
var imagePicker = campingPage.Value<IPublishedContent>("images");
My guess is based on this line in the source code:
I'm wondering if in the View that ModelsBuilder isn't being quite so clever and the generated Images property is an IEnumerable<IPublishedContent> and that's why it works...
Ok I've got it working, but I'm not sure why. It's definitly related to the changes in .Children and .Children() (with the culture)
In my Controller I've changed the code to use .Children, and it works... Whilst in my Templatepage I'm using .Children()
GG ;-)
Final code:
var imagePicker = campingPage.Images;
var imageUrl = "/placeholder.jpg";
if (imagePicker != null)
{
if (imagePicker.Children.Any())
{
var image = imagePicker.Children.First();
Cant get children of Mediafolder
Hi,
I've just updated to 8.1.5 and am having the following issue.
Old code in a controller:
Only this has stopped working. I've been trying for a few hours now and am quite stuck. The mediafolder always has 'null' children.
All of these(except the MediaId) result in a null value when adding .Children().. However, it ofcourse DOES have children.
Fun fact when having similar code on a normal TemplatePage, it DOES work
Hope anyone has an idea, bit stuck right now x)
Hi Ambert
Is your Media Picker configured to pick multiple items? or a single folder?
I wonder if in the controller the PropertyValueConverter is being clever and detecting that only a single media item is pickable and therefore the item is convertable to an IPublishedContent item rather than an IEnumerable
eg try:
My guess is based on this line in the source code:
https://github.com/umbraco/Umbraco-CMS/blob/3bfd9b71e290354744d677440983ecd06c5c0788/src/Umbraco.Web/PropertyEditors/ValueConverters/MediaPickerValueConverter.cs#L37
I'm wondering if in the View that ModelsBuilder isn't being quite so clever and the generated Images property is an
IEnumerable<IPublishedContent>
and that's why it works...regards
Marc
Ok I've got it working, but I'm not sure why. It's definitly related to the changes in .Children and .Children() (with the culture)
In my Controller I've changed the code to use .Children, and it works... Whilst in my Templatepage I'm using .Children()
GG ;-)
Final code:
Seems to be some kind of cache issue why its still working in the templates.. After checking a few days later, that stopped working too... GG ;-)
is working on a reply...