If you are using the standard Checkbox List datatype they will come back as a comma delimited list of values. eg hello,world
You just need to take the value and split it on the comma.
If you are using Umbraco MVC Views or partials.
@{
var yourVals = Model.Content.GetPropertyValue<string>("yourCheckBoxListVal").Split(',');
}
<ul>
@foreach(var val in yourVals){
<li>@val</li>
}
</ul>
Your code works so it's a good step in the right direction. Although I am trying to print a bunch of content items on a overview page and if I try to add your code into the existing foreach it doesn't work.
I have the following structure:
@foreach (var item in dinnerItems)
{
<div id="dinnerItems">
<a href="@item.Url">@item.Name</a>
on
@String.Format("{0:dd-MM-yyyy}", item.EventDate)
at
@item.Country | @item.Address
//This is where I want to print the properties of the checkbox
</div>
}
@foreach (var item in dinnerItems)
{
<div id="dinnerItems">
<a href="@item.Url">@item.Name</a>
on
@String.Format("{0:dd-MM-yyyy}", item.EventDate)
at
@item.Country | @item.Address
//This is where I want to print the properties of the checkbox
<ul>
@foreach(var val in item.CheckBoxProperty.Split(',')){
<li>@val</li>
}
</ul>
</div>
}
Hi, so I'm trying to do the exact same thing, but my DataType is applied to a 'Member', not a regular content item. It seems that the referencing ID's are stored, not a text representation? I'm not sure how to get what the text should be for these values.
Displaying prevalues from selected checkbox
Hey everyone,
I have a checkbox with X amount of options and I want to print the prevalues of those that are selected on my page.
If anyone could help me out it will be greatly appreciated!
Hey Desley
If you are using the standard Checkbox List datatype they will come back as a comma delimited list of values. eg hello,world
You just need to take the value and split it on the comma.
If you are using Umbraco MVC Views or partials.
Hi Peter,
Your code works so it's a good step in the right direction. Although I am trying to print a bunch of content items on a overview page and if I try to add your code into the existing foreach it doesn't work.
I have the following structure:
My apologies for not being quite clear enough.
Ahhh! you are using Dynamics.
Try this..
Perfect. Thank you!
Hi, so I'm trying to do the exact same thing, but my DataType is applied to a 'Member', not a regular content item. It seems that the referencing ID's are stored, not a text representation? I'm not sure how to get what the text should be for these values.
Edit: Should point out, this is 7.1 RC
Edit: Pretty sure this is actually a bug, have created a ticket here: http://issues.umbraco.org/issue/U4-4575
is working on a reply...