Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 karma points
    Nov 08, 2019 @ 07:44
    Claushingebjerg
    0

    check specific checkbox list value

    I have a checkboxlist in v8, and i need to check it for values and do something, if a specific checkbox is set...

    Iknow i can get the values by doing

    foreach(var s in Model.Value<IEnumerable<string>>("type")){
    <text>@s</text>
    }
    

    But how do i check if one of the values is "foo"?

  • Adrian 3 posts 71 karma points
    Apr 15, 2020 @ 07:13
    Adrian
    0

    I am sure this could be better but this is working for me. I only have a couple roles setup so an if condition like this isn't much trouble.

    foreach(var person in people){
        var roles = person.Value<IEnumerable<string>>("memberRoles");
    
        foreach(var role in roles){
            if(role == "Site Selection"){
                <h2>@person.Name</h2>
            }
        }
    
    }
    
  • Greg Jenson 24 posts 157 karma points
    Aug 26, 2020 @ 16:01
    Greg  Jenson
    1

    There is probably a more elegant way to to this, but I am at least getting the results I want:

    var team = Umbraco.Content(Guid.Parse("123456789"))
    .ChildrenOfType("teamMember")
    .Where(x => x.IsVisible());
    @foreach(var item in team) {
        foreach(var g in item.Value<IEnumerable<string>>("group")) {
            if( g == "foo" ) {
                <p>@item.Value("yourField")</p>
            }
        }            
    }
    

    If anyone has an improved response, I'd like to see it.

  • louisjrdev 11 posts 84 karma points
    Nov 29, 2021 @ 13:40
    louisjrdev
    0

    Try:

    if(Model.Value<IEnumerable<string>>("type").Any(x => x == "foo")){
        //My conditional logic if value is "foo"
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft