It took me a while to figure it out, so I thought I'd share it here too.
Solution either type it correctly for the thing you are working with, or use the GetRawValue method.
Get Value
foreach (var item in Model.Items.Where(x => x != null))
{
var test = item.GetValue<string>("images");
@test // outputs: system.int32[]
}
GetValue IEnum
foreach (var item in Model.Items.Where(x => x != null))
{
var test = item.GetValue<IEnumerable<int>>("images");
foreach (var x in test)
{
@x // outputs: 112711261128
}
}
GetRawValue
foreach (var item in Model.Items.Where(x => x != null))
{
var test = item.GetRawValue("images");
@test // outputs: 1127,1126,1128
}
GetValue returning 'system.int32[]', rather than Value
Use case: Storing a collection of Images (e.g. array on Ints)
When using GetValue the type is returned rather than the items.
I think this is caused by having the Umbraco Core Property Value Converters installed.
It took me a while to figure it out, so I thought I'd share it here too.
Solution either type it correctly for the thing you are working with, or use the GetRawValue method.
Get Value
GetValue IEnum
GetRawValue
Git Commit with GetRawValue
is working on a reply...