Copied to clipboard

Flag this post as spam?

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


  • Radek 11 posts 142 karma points
    Jun 06, 2019 @ 20:06
    Radek
    0

    Filtering by dropdown value

    Why doesn't below code work?

    var childrenInCat = Model.Parent.Children.Where<BlogPost>(x => x.blogPostCategory = category);
    

    I get "Type IEnumerable is Defined in an assembly that is not reference.

    Top of the page reads:

    @inherits UmbracoViewPage<BlogPost>
    

    I am using the v8 compatible notation.

    I've tried to follow documentation by appears that the only overload for Where I can use is Where<>(), documentation shows all examples with Where()

    https://our.umbraco.com/Documentation/Reference/Querying/IPublishedContent/Collections

    Really lost at this point.

  • Mario Lopez 168 posts 952 karma points MVP 3x c-trib
    Jun 06, 2019 @ 21:52
    Mario Lopez
    0

    I guess you have tried removing the <BlogPost> part? That should be inferred from the Children type which is IEnumerable<IPublishedContent>. If you want to cast them to BlogPost you can do:

    Model.Parent.Children.Where(x => x.Id == 123).Select(x=> new BlogPost(x));
    

    If you want to filter the children by doctype you can do:

    Model.Parent.Children.OfType<BlogPost>()
    
  • Radek 11 posts 142 karma points
    Jun 07, 2019 @ 01:54
    Radek
    100

    Ok so this turned out to be some sort of .NET Visual Studio issue.

    I've Googled the exception what was showing up when debugging the page.

    you must add a reference to assembly 'netstandard, version=2.0.0.0, culture=neutral, publickeytoken=cc7b13ffcd2ddd51'.

    Solution was to add following to Web.Config

    <assemblies>
            <add assembly="netstandard, Version=2.0.0.0, Culture=neutral, 
                PublicKeyToken=cc7b13ffcd2ddd51"/>
    
Please Sign in or register to post replies

Write your reply to:

Draft