Copied to clipboard

Flag this post as spam?

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


  • Brian McNally 16 posts 104 karma points
    Jul 11, 2014 @ 21:11
    Brian McNally
    0

    Question with MVC Partial view where() filtering syntax for array

    I'm trying to filter out results in a foreach loop (umbraco7 MVC rendering partial view). I've been using individual checkboxes for the datatype objects I'm pulling in, and that seems to work but doesn't look great for the content editors. So they currently check individual checkboxes for an item. In this example say a site asset can be checked as value1, value2, value3 and so on.

    Then in the for each loop I am filtering out using the following:

     @foreach (var myItem in myNode.Children.Where("Visible").Where("value1 == true"))
                            {
    <li>@myItem.name</li>
    }

    This works but I'd like to switch from individual checkboxes for each value to a multiselect list or checkbox list. this obviously creates an array of values. My Problem is that I just can't figure out the syntax in the foreach loop to say that it contains the values I'm looking for...Hope this question makes sense.

    I'd like to do something like below but am obviously not clear on the syntax or how to accomplish this. Searching an array for a value rather than just checking if a boolean is true or not.

    @foreach (var myItem in myNode.Children.Where("Visible").Where("myCategories 'contains' value1"))
                            {
    <li>@myItem.name</li>
    }
Please Sign in or register to post replies

Write your reply to:

Draft