Copied to clipboard

Flag this post as spam?

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


  • Jesper Skjønnemand 33 posts 257 karma points
    1 week ago
    Jesper SkjĂžnnemand
    0

    Hello I am trying the following:

    • Create a list of my schools (document type)
    • For each school on my list I want to
      • Create a list of available courses (multinode tree picker)
      • Check if that list contains the current page
      • If it does: Write Url and Name of the school page

    So far my template looks like this:

      @{
        var currentCourse = Model.Content.Id;
        var mySchools = Model.Content.Site().Descendants("Skole").ToArray();
            foreach(var item in mySchools) 
            {
            var schoolCourses = item.GetPropertyValue<IEnumerable<IPublishedContent>>("selectedCourses").ToArray();
            if (schoolCourses.Contains("CurrentCourse") == true)
                {
                <a href="@item.Url">@item.Name</a>
                }
            }
        }
    

    Umbraco does not like this line:

    if (schoolCourses.Contains("CurrentCourse") == true)
    

    I get this Compilation Error:

    CS1929: 'IPublishedContent[]' does not contain a definition for 'Contains' and the best extension method overload 'Queryable.Contains<string>(IQueryable<string>, string)' requires a receiver of type 'IQueryable<string>'
    

    What do I need to change? Best

  • Jonathan Distenfeld 97 posts 534 karma points
    1 week ago
    Jonathan Distenfeld
    0

    Hi Jesper,

    try referencing namespace "System.Linq" on top of your template.

    @using System.Linq;

    ~ Jonathan

Please Sign in or register to post replies

Write your reply to:

Draft