It is the checkbox list data type that I am using. Lets say I have values 1, 2, 3, 4, 5 available to be selected in the backend. If I select values 2 and 3 then my loop will only print these two values. I would like it to print 1, 2, 3, 4, 5 even if they haven't been selected.
That is correct since your property value only contains a reference to the items selected. It is technically possible to get the whole list, but you will need to inject the IDataTypeService into your view, you can then do something like this
@{
var cblDataType = dataTypeService.GetDataType("Home - Checkbox list");
var config = (Umbraco.Cms.Core.PropertyEditors.ValueListConfiguration)cblDataType.Configuration;
foreach (var item in config.Items)
{
if (Model.CheckBoxTest.Contains(item.Value))
{
<input type="checkbox" value="@item.Value" checked /> @item.Value
}
else
{
<input type="checkbox" value="@item.Value" /> @item.Value
}
}
}
Loop through and display checbox items
I am trying to loop through and display ALL the items in my checkbox list but it only displays the ones that I have checked.
It is the checkbox list data type that I am using. Lets say I have values 1, 2, 3, 4, 5 available to be selected in the backend. If I select values 2 and 3 then my loop will only print these two values. I would like it to print 1, 2, 3, 4, 5 even if they haven't been selected.
Hi macleodmorgan,
That is correct since your property value only contains a reference to the items selected. It is technically possible to get the whole list, but you will need to inject the IDataTypeService into your view, you can then do something like this
is working on a reply...