I have a custom blocklist property as part of a document type. It's very simple and only accepts one block component type. I am trying to access this property in my code. While following the umbraco documentation here:
https://docs.umbraco.com/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/block-editor/block-list-editor,
It tells me it returns an IEnumerable
. On that same page, it says that I can pull the value as that or BlockListModel... but with either, it returns null.
if (content.HasProperty("locations"))
{
var locations = content.GetValue<BlockListModel>("locations");
(or)
var locations = content.GetValue<IEnumerable<BlockListItem>>("locations");
...
}
If I pull the value as a string or dynamic object, it will show as:
{"layout":{"Umbraco.BlockList":[{"contentUdi":"umb://element/74437d1928534a9287430056e140b99b"},{"contentUdi":"umb://element/382ddba6783948b28696798b3b6dad16"}]},"contentData":[{"contentTypeKey":"0285ad7f-763f-4bc5-80be-45f85f8a39e6","udi":"umb://element/74437d1928534a9287430056e140b99b","city":"Colville","stateA":"[\"WA\"]","name":"Colville Toyota"},{"contentTypeKey":"0285ad7f-763f-4bc5-80be-45f85f8a39e6","udi":"umb://element/382ddba6783948b28696798b3b6dad16","stateA":"[\"OR\"]","name":"Coos Bay Toyota","city":"Coos Bay"}],"settingsData":[]}
In converting to the BlockListModel, it has to be erroring causing it to return null; right? I need to pull the values this way because I am using those values to calculate other properties and then save that property to the document.
Anyone running into this or have a solution? Is this enough info? I feel like I've tried quite a bit without success.