[Solved] Contentment cast
# help-with-umbraco
c
V13.2.2 Just putting a forms prevalue function together. It needs to list the items in a Contentment Data List. However, I'm having trouble with casting. I have this:- var preValSourceNode = iPub.GetProperty("locationList") as IEnumerable; Where iPub is an IPublishedContent - which is the page that contains the Data Item List which is called "locationList". preValSourceNde ends up as null. I need preValSourceNde to go into a foreach loop so need it as an IEnumerable. Unfortunately I can't use ModelsBuilder at this point as the iPub is provided by the user picking a document from a list. Any hints would be appreciated. Thanks.
j
If you put a breakpoint in, what is
iPub.GetProperty("locationList")
telling you the type is? 🙂
a
GetProperty("locationList")
get you the property, not the property value - which is why the cast fails
j
You're right, I missed that too! It should be
.Value("locationList")
, yeah?
c
Yay, that was it. Thanks. I'd had my head stuck in a ViewComponent. You're right, setting it to
var preValSourceNode = iPub.Value<IEnumerable<DataListItem>>("locationList");
got it working. I could have sworn I'd tried that earlier and it blew up. But anyway, thanks very much for your help 🙂
4 Views