Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Marcus 9 posts 99 karma points
    Jul 11, 2019 @ 11:47
    Marcus
    0

    Problem getting image url (System.Collections.Generic.List contains no definition for FirstOrDefault)

    Hi!

    I have a little product showcase site and I'm trying to list "similar products" at the bottom of the product page. These similar products are based on if they have the same "category" property value.

    The code I have so far works except when I'm trying to get the product image url. Then I get the error System.Collections.Generic.List

    var productCategory= Model.Content.GetPropertyValue("productCategory");
    var productList = Umbraco.Content(2160);
    var similarProducts = productList.Descendants("product").Where("Visible").Where("@productCategory.ToString().Contains(@0)", productCategory);
    
    @foreach (var similarProduct in similarProducts.Random(4))
    {
         <h2>@similarProduct.GetPropertyValue("title")</h2>
         <img src="@similarProduct.GetPropertyValue("images").FirstOrDefault().Url
    }
    

    I can't figure why the image not showing (I'm using multi media picker for the images and need to get the first one)?

    A little help would be much appreciated! :)

Please Sign in or register to post replies

Write your reply to:

Draft