[SOVLED] How to check if a certain node ID is sele...
# help-with-umbraco
m
Each content page has a Mutinode Treepicker, not manditory, and I want to check if taht picker has an entry for a specific contentNode.Id selected and if so return the iPublishedContent object for the node for further usage. I have been playing around with a .Where () clause trying to figure out how to read the property correctly with no luck. I did look into the documentation but it shed no light either. Can anyone enlighten me on how to read into the property and check for that Id? Thanks
l
Copy code
var targetId = 1234;
var multiNodeProp = CurrentPage?.Value<IEnumerable<IPublishedContent>>("alias");
var targetPage = multiNodeProp?.FirstOrDefault(x => x.Id.Equals(targetId));
The above should give you what i think youre after, targetId needs to be updated to your actual ID, "alias" needs updating to your alias of the multinode treepicker alias. If targetPage is null, nothing was found under the targetId, if its populated, it will be the IPublishedContent of the page by targetId
I pseudocoded the above, so take it with a pinch of salt
I also would suggest storing your target page in some settings page or something, so you dont have the targetId hard coded
m
I am writting this up in a class file that gets called by a razor page. The page is responsible for passing in the right Id value, the class is responsible for finding the proper nodes and returning them to the razor page.
It does not look like that works. mutiNodeProp is an iPusblishedContent type which can't be used in a Where clause. .Where(x => x?.Value<IEnumerable>("primaryAuthor").FirstOrDefault(y => y.Id.Equals(authorID))); throws a cannot implicitly convert typoe iPublishedContent to bool error.
l
x.Value("primaryAuthor") above, is that the multiNode tree picker?
m
Yes, "primaryAuthor" is the property name for the picker. Sorry I did not respond earlyer, I work over nights and was dead tired so went to sleep.
l
If you want to hop into the voice chat today and screenshare, im sure we can get to the bottom of this, will be the quickest / easiest way? @Matthew Alexandros
m
I am at work for about another hour but sure we can screen share.
I will ping you when I get home.
@Lewis Heaton I am home know if you would like to do the share
l
ready when you are @Matthew Alexandros
m
Cool, heading into VC now
Thanks again for the quick help @Lewis Heaton For anyone that is looking at this for a solution here is the correct code Lewis was able to help me build
Copy code
.Where(x => x?.Value<IEnumerable<IPublishedContent>>("primaryAuthor")?.Any(y => y.Id.Equals(authorID)) ?? false)
4 Views