Copied to clipboard

Flag this post as spam?

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


  • Bent Holz 100 posts 273 karma points
    May 18, 2018 @ 08:44
    Bent Holz
    0

    List pages that have specific page id in property value

    I am trying to list employees who work in a specific department. An employee can be in more than one department.

    I have used nuPickers to add a checkbox property to my Employee Document Type, so that I can select witch departments the person works in.

    If I render out an employee, the values for the departments the person works in are page id's of the relevant departments (ex. "1045,1056,1061...").

    My code looks like this

       @{
        var selection = Model.Content.Site().FirstChild("ansatte").Children("ansat")
                            .Where(x => x.IsVisible());
    }
    <ul>
        @foreach(var item in selection){
            <li>
                <a href="@item.Url">@item.Name</a>
            </li>
        }
    </ul>
    

    I need to add something like:

    .Where(x => x.IsVisible() && ansatAfdeling = 1045);
    

    But am not getting it to work... Any suggestions?

  • Frans de Jong 548 posts 1840 karma points MVP 3x c-trib
    May 18, 2018 @ 08:55
    Frans de Jong
    0

    If you add this to your where it should work (although not the most elegant solution):

    @{
        var selection = Model.Content.Site().FirstChild("ansatte").Children("ansat").Where(x => x.IsVisible() && x.GetPropertyValue<string>("departments").Split(',').Contains(1234));
    
    }
    
  • Bent Holz 100 posts 273 karma points
    May 18, 2018 @ 09:25
    Bent Holz
    0

    I get the following error:

    Compiler Error Message: CS1593: Delegate 'System.Func

    Code looks like this:

        @{
         var selection = Model.Content.Site().FirstChild("ansatte").Children("ansat")
                .Where(x => x.IsVisible() && x.GetPropertyValue<string>("ansatAfdeling").Split(',').Contains(1030));
    }
    <ul>
        @foreach(var item in selection){
            <li>
                <a href="@item.Url">@item.Name</a>
            </li>
        }
    </ul>
    
Please Sign in or register to post replies

Write your reply to:

Draft