Copied to clipboard

Flag this post as spam?

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


  • Seth Hoveland 3 posts 83 karma points
    Jan 27, 2017 @ 21:35
    Seth Hoveland
    0

    Filtering Data by custom data type

    Just getting started in trying to figure Umbraco and MVC out, so I appreciate your patience in advance.

    I have a partial view that is loading lesson plans. The lesson plan document Type has a Checkbox list that specifies an age range (Early Elementary, Late Elementary, etc...). I'd like to be able to list out specific age ranges for ease of consumption (i.e. first list is only Early Elementary, second is Late Elementary, etc...). Would this be best accomplished in the 'Where' clause of the loop? Is there a good example of syntax for listing by checkbox list value? Thanks!

    Seth

  • Ivan 15 posts 125 karma points
    Jan 27, 2017 @ 23:04
    Ivan
    0

    Hi Seth. In my case for such purposes (with ranges) I have created custom property using Umbraco.DropDown with alias rangeproperty. And you insert predifined values: like alabama, oklahoma, etc.

    And filtering according to those values goes something like this:

    Where("Visible && rangeproperty.Contains(@0)","alabama")

    Hope that helps. Ivan

  • Seth Hoveland 3 posts 83 karma points
    Jan 30, 2017 @ 14:51
    Seth Hoveland
    0

    Thanks so much for your response! I am not having much luck though - chock it up to general inexperience on my part.

    The alias of my checkbox list is "ageRange" - so I was assuming it would look like this. Is something glaringly wrong with what you see below? would it be different syntax for a checkbox list?

    @{
    var lessonPlans = Umbraco.Content(1253);
    
        foreach (var lessonPlan in lessonPlans.Children.Where("Visible && ageRange.Contains(@0)","Early Elementary"").OrderBy("createDate descending"))
        {
    
                <div class="col-sm-12 col-md-6">
                    <h5>@lessonPlan.Name</h5>
                    <p><strong>Age Range:</strong> @lessonPlan.ageRange</p>
                    <p><strong>Description:</strong> @lessonPlan.Description</p>
                    <a href="@lessonPlan.File" class="btn btn-md btn-black-line">Download</a>
    
                </div>
    
        }
    

    }

  • Ivan 15 posts 125 karma points
    Jan 31, 2017 @ 21:46
    Ivan
    0

    I dont know how it goes for checkboxlist, why dont you change your variable to dropdown and code should work for you.

    EDIT:

    seems like you have extra " in your where statement, right at the end:

    "Visible && ageRange.Contains(@0)","Early Elementary" "

    Try putting this in where() "Visible && ageRange.Contains(@0)","Early Elementary". Following logic worked for me.

Please Sign in or register to post replies

Write your reply to:

Draft