Copied to clipboard

Flag this post as spam?

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


  • Rick 36 posts 150 karma points
    Dec 26, 2017 @ 14:21
    Rick
    0

    Getting Checkbox List Values

    Hello All,

    Using Umbraco 7.7 here and having an issue getting the selected values from a checkbox list.

    I created the new data type with the Checkbox List property editor and loaded a few values. I added the custom datatype to my document type, checked a couple options and published it.

    In my code-behind, I'm iterating through a bunch of child nodes and creating a simple list of the nodes attributes one of which is the selected options for the checkbox data type. (e.g. - going through a list of case studies and for each case study, show the categories that the study applies to.

    I've tried this documentation with no success: https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/checkbox-list

    @foreach (var cs in csHome.Children.Where("Visible")) {
        <div>
            <div>Display Name: @cs.displayName</div>
            <div><a href="@cs.study">Link</a></div>
            <div>CS CB: @cs.studyProducts2</div>
            @if (cs.HasValue("studyProducts2")) {
                foreach (var x in cs.studyProducts2.Split(',')) {
                    <div>@x</div>
                }
            }
        </div>
        <hr/>
    }
    

    ....which gives the error "object does not contain a definition for 'Split'"

    I've also tried this solution which gives the same error: https://our.umbraco.org/forum/using-umbraco-and-getting-started/86221-handling-checkbox-list-in-76-with-new-property-value-converters

    I've done this in earlier versions of Umbraco and am just not sure what I'm missing.

    Thank you in advance...

  • Matthew Wise 271 posts 1373 karma points MVP 5x c-trib
    Dec 26, 2017 @ 17:09
    Matthew Wise
    0

    Hi Rick,

    Are you using Content Models by any chance?

    If so then the studyProducts2 is already an IEnumerable<string>

    Cheers

    Matt

  • Matthew Wise 271 posts 1373 karma points MVP 5x c-trib
    Dec 26, 2017 @ 17:13
    Matthew Wise
    0

    It looks like you are using dynamic the more I look at it.

    You may want to look into the Models builder as Dynamics have a performance hit https://our.umbraco.org/documentation/Reference/Common-Pitfalls/#dynamics

  • Rick 36 posts 150 karma points
    Dec 26, 2017 @ 20:12
    Rick
    101

    @Matthew,

    The models were already enabled by default in 7.7.7 but for some reason it didn't see the structure of the field with Content.GetPropertyValue, but it didn't help me find the one forum note with the answer.

    As you mentioned, it was already an IEnumberable which did confuse me as to why I couldn't iterate it the way I had in the past. This was the solution.

    @foreach(var s in cs.GetPropertyValue<IEnumerable<string>>("studyProducts2")) {
                <div>S: @s</div>
    }
    

    Thanks for the insight!

Please Sign in or register to post replies

Write your reply to:

Draft