I don't understand why I am getting this error. All my templates has a single master template. I'm also not sure what index parameter the error is referring to.
I think for some reason one of your forsideCarouselBilleder carousel images is null and so when you retrieve your items there is nothing in the list when you call ToList() and so when you use [0] to read the first indexed item in the List, you are getting the error message that the index is out of range!
I would probably consider breaking down the access to the Url into steps, as this gives you a clearer idea for debugging, just where it is going wrong, eg:
@{
var carouselImages = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("forsideCarouselBilleder").Where(f=>f!=null);
//first or default will retrieve the first item in a list/enumerable or null if there is not one there
var carouselImage = carouselImages.FirstOrDefault();
}
//then you can safely write out the image tag if the image exists
@if(carouselImage != null){
<img src="@carouselImage.Url" />
}
"Index was out of range." error when setting src attribute of image on front page
I have a carousel element on my front page, on which i want to display 3 images. I've set the src attribute of the images to this:
With an incremented index for each image. This works fine on another page on my project, which is on the same level in my tree as my front page.
But when i load up the front page with this code, i get this error:
http://i.imgur.com/UzwElyt.png
I don't understand why I am getting this error. All my templates has a single master template. I'm also not sure what index parameter the error is referring to.
I think for some reason one of your forsideCarouselBilleder carousel images is null and so when you retrieve your items there is nothing in the list when you call ToList() and so when you use [0] to read the first indexed item in the List, you are getting the error message that the index is out of range!
I would probably consider breaking down the access to the Url into steps, as this gives you a clearer idea for debugging, just where it is going wrong, eg:
regards
Marc
I'm getting a different error now.
"CS0019: Operator '>' cannot be applied to operands of type 'method group' and 'System.Collections.Generic.IEnumerable
At this line:
Am I missing some references?
Edit: Nevermind, I fixed it :)
Typo! :-P
is working on a reply...