Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have created a folder in Umbraco and I would like to display a random image from that folder on my page.
I found a solution from a few years ago which was giving me compile errors
dynamic folder = Library.MediaById(1054); var randomImage = folder.Children.Where("nodeTypeAlias = \"Image\"").Random();
I found that I have to add the proper inherits in my file
@using umbraco.MacroEngines @inherits DynamicNodeContext
but this it gives me an error because I already have a @model I'm using in the first line
The 'inherits' keyword is not allowed when a 'model' keyword is used.
Thanks for any help
Can you do the following?
var folder = Umbraco.TypedMedia(1054); var randomImage = folder.Children().Where(x => x.DocumentTypeAlias == "Image").Random();
Hi Kilgore,
The problem is with the header of your view.
You can't use model and inherits directives.
Also do not use dynamic types, it will be easier to manage this code after.
Thanks,
Alex
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Randomly selecting an image from a folder
I have created a folder in Umbraco and I would like to display a random image from that folder on my page.
I found a solution from a few years ago which was giving me compile errors
I found that I have to add the proper inherits in my file
but this it gives me an error because I already have a @model I'm using in the first line
Thanks for any help
Can you do the following?
Hi Kilgore,
The problem is with the header of your view.
You can't use model and inherits directives.
Also do not use dynamic types, it will be easier to manage this code after.
Thanks,
Alex
is working on a reply...