Copied to clipboard

Flag this post as spam?

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


  • Jeppe Volander Rasmussen 16 posts 138 karma points
    Aug 13, 2018 @ 20:25
    Jeppe Volander Rasmussen
    0

    Checklist values

    Hey guys,

    Im trying to list all the values in my checkbox list and If they're checked i need to wrap them in a div with the class "gotvalue". I found this code below, which just lists all my values. Im not sure on how to proceed from here - Got any suggestions?

     @{
                        var dataType = ApplicationContext.Services.DataTypeService.GetDataTypeDefinitionByName("Diet Direction");
                        var preValues = ApplicationContext.Services.DataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id).PreValuesAsDictionary.Select(x => x.Value).ToList();
    
                        var allTags = preValues;
                        }
                        @foreach (var item in allTags)
                        {
    
                        if(@item.Value != null) {
                        <div class="gotvalue"><a href="@item.Value">@item.Value</a></div>
                        }
                        else {
                         <div class="gotnovalue"><a href="@item.Value">@item.Value</a></div>
                        }
    
                        }
    
  • Nick Hoang 51 posts 180 karma points c-trib
    Oct 15, 2019 @ 04:31
    Nick Hoang
    0

    You have to compare with checked option of your content, something like this

    @{
                    var selectedOptions = YourContent.GetPropertyValue<IEnumerable<string>>("YourFieldName");
                    var dataType = ApplicationContext.Services.DataTypeService.GetDataTypeDefinitionByName("Diet Direction");
                    var preValues = ApplicationContext.Services.DataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id).PreValuesAsDictionary.Select(x => x.Value).ToList();
    
                    var allTags = preValues;
                    }
                    @foreach (var item in allTags)
                    {
    
                    if(selectedOptions.Contains(item.Value)) {
                    <div class="gotvalue"><a href="@item.Value">@item.Value</a></div>
                    }
                    else {
                     <div class="gotnovalue"><a href="@item.Value">@item.Value</a></div>
                    }}
    
Please Sign in or register to post replies

Write your reply to:

Draft