Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Currently upgrading a project to Umbraco 7.6 which uses the checkbox datatype.
Used to be
@foreach var item in Model.Content.GetPropertyValue
Now returns System.Linq.Enumerable+WhereSelectArrayIterator`2[System.String]
The value without spiting returns System.Linq.Enumerable+WhereSelectArrayIterator`2[System.String,System.String]
Any idea on what cast I need to do?
John
Hi John,
In v7.6 this package got integrated in to the core : https://our.umbraco.org/projects/developer-tools/umbraco-core-property-value-converters/
This means that now out of the box property values will be converted to some strongly typed model.
If you want you can disable this feature in the umbracoSettings.config file. Look for this setting and set it to false :
<EnablePropertyValueConverters>true</EnablePropertyValueConverters>
But if you want to use the value converters you can use this code.
@foreach(var item in Model.Content.GetPropertyValue<IEnumerable<string>>("alias") { @item }
The value converter for the checkbox list returns a IEnumerable of type string.
See the source code for the converter : https://github.com/umbraco/Umbraco-CMS/blob/dev-v7.6/src/Umbraco.Core/PropertyEditors/ValueConverters/CheckboxListValueConverter.cs
But may I can suggest to use the models builder. This will generate strongly typed models. The object type of your property will be set to the correct type based on the converter when the model is generated.
Read this document to have a good idea how the models builder works : http://24days.in/umbraco-cms/2016/getting-started-with-modelsbuilder/
Dave
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Checkbox Umbraco 7.6
Currently upgrading a project to Umbraco 7.6 which uses the checkbox datatype.
Used to be
@foreach var item in Model.Content.GetPropertyValue
Now returns System.Linq.Enumerable+WhereSelectArrayIterator`2[System.String]
The value without spiting returns System.Linq.Enumerable+WhereSelectArrayIterator`2[System.String,System.String]
Any idea on what cast I need to do?
John
Hi John,
In v7.6 this package got integrated in to the core : https://our.umbraco.org/projects/developer-tools/umbraco-core-property-value-converters/
This means that now out of the box property values will be converted to some strongly typed model.
If you want you can disable this feature in the umbracoSettings.config file. Look for this setting and set it to false :
But if you want to use the value converters you can use this code.
The value converter for the checkbox list returns a IEnumerable of type string.
See the source code for the converter : https://github.com/umbraco/Umbraco-CMS/blob/dev-v7.6/src/Umbraco.Core/PropertyEditors/ValueConverters/CheckboxListValueConverter.cs
But may I can suggest to use the models builder. This will generate strongly typed models. The object type of your property will be set to the correct type based on the converter when the model is generated.
Read this document to have a good idea how the models builder works : http://24days.in/umbraco-cms/2016/getting-started-with-modelsbuilder/
Dave
is working on a reply...