I only get the ones selected in an string like this Item1, Item2, Item3 what if I need them all to be displayed on the frontend and only the one selected in bold how would I select them all.
I like this question a lot, however the answer is a bit complex and requires using a few services!
@{
if (Model.Content.HasValue("superHeros"))
{
var selectedValues = Model.Content.GetPropertyValue<string>("superHeros").Split(',');
var propertyTypeAlias = Model.Content.GetProperty("superHeros").PropertyTypeAlias;
var documentTypeAlias = Model.Content.DocumentTypeAlias;
var propertyType = ApplicationContext.Services.ContentTypeService.GetContentType(documentTypeAlias).PropertyTypes.FirstOrDefault(x => x.Alias == propertyTypeAlias);
if (propertyType != null)
{
var dataTypeId = propertyType.DataTypeDefinitionId;
var preValues = ApplicationContext.Services.DataTypeService.GetPreValuesByDataTypeId(dataTypeId);
foreach (var preValue in preValues)
{
if (selectedValues.Contains(preValue))
{
<li><strong>@preValue</strong></li>
}
else
{
<li>@preValue</li>
}
}
}
}
}
Because this requires quite a few management API's to get the answer, I would recommend using a cached partial view so that it's not hitting the DB a lot.
get all items from Umbraco.CheckBoxList
I hope this is an easy question.
If I get items from the Umbraco.CheckBoxList like this
I only get the ones selected in an string like this Item1, Item2, Item3 what if I need them all to be displayed on the frontend and only the one selected in bold how would I select them all.
Hi Dan,
I like this question a lot, however the answer is a bit complex and requires using a few services!
Because this requires quite a few management API's to get the answer, I would recommend using a cached partial view so that it's not hitting the DB a lot.
Jeavon
@foreach (var n in ApplicationContext.Services.DataTypeService.GetPreValuesByDataTypeId(datatypeid).ToList())
{
@n
}
Sorry for the late response Jeavon Leopold and John Churchley I have been on a vacation for some days :D.
I appreciate the answers !
I tried your solution Jeavon and it worked great thanks !
Cool, looking back at it now I might put the propertyAlias into a variable to avoid it being there three times, e.g.
is working on a reply...