Can't access properties of Multinode Treepicker
# help-with-umbraco
m
I am trying to use the Multinode Treepicker and am following the at https://docs.umbraco.com/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/multinode-treepicker. The Picker is setup and a property of the "About Us" page allowing you to pick from the content type "Team Member" and it worked. I was able to pick the member and save the doc but now when I am trying to programicly display the information I can't see to access any of the team member properties. Here is my code set but both methods of accessing the "Display Name" of the team member give the error "IPublishedCointent does not contain a definition for 'displayName' and no accessile extension method 'displayName' accepting a first argument of type 'IPublishedCOntent' could be found (are you missing a using directive or an assemly reference?)" I presume I am missing something the document is not covering but I don't know what, do I need to inject the Team Members type or add a some using statment? Below is my code. Thanks for the help. @using Umbraco.Cms.Web.Common.PublishedModels; @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage @using ContentModels = Umbraco.Cms.Web.Common.PublishedModels; @{ Layout = "_layout.cshtml"; } @{ var teamMemberList = Model.TeamMembers; foreach (var teamMember in teamMemberList) { @teamMember.displasyName } } @{ var teamMemberList2 = Model.Value<IEnumerable>("teamMembers"); if (teamMemberList2 != null) { foreach (var teamMember in teamMemberList2) { @teamMember.displayName } } } https://cdn.discordapp.com/attachments/1166152377603215360/1166152377754198056/Screenshot_2023-10-23_190604.png?ex=65497308&is=6536fe08&hm=3d88d0c18f62ef4e22ba451cb03cd8ad566dbe312f113ac74d3801fca489aa4d&
d
Hi there! The type of
teamMemberList
is probably
IEnumerable<IPublishedContent
. Before you can access strongly typed properties on such a model, you have to cast it to the proper type. Alternatively, you can use the weakly typed alternative and call
.Value<string>("displayName")
on
IPublishedContent
directly
m
Sorry I am not foloowing. I just created a new mutinode picker datatype and set a name and starting content type, everything else was left to default. Is there something missing from the document i am following or did i configure it wrong or is the document assuming some other setup?
s
You can either cast the list of items to teammember or you could try to use @teammember.value(nameof(TeamMember.DisplayName)) (check If capitals are correct, looking at it from a phone atm.
m
But why is it if I am following the documention it is not working?
s
In the documentation they render the Name property, which is the node name. That property is always available
As every node always has a required name
m
Ok. I see now how would I update my first foreach loop to cast to the right type?
s
Something like Var teamMemberList = Model.TeamMembers.Cast() Maybe it is SafeCast, always forget which one of the 2 it is without intellisense
m
Thanks. When I get home from work I will try that code and see what happens. No worries on not 100% knowing I did not know at all and at worst this gives me a jump point and at pedt (and most probible) get me working.
s
Awesome, have a great day
m
Thanks. You too
I just got home and updated my code, you where 99% there. It was .Cast but instead fo TeamMember it was TeamMemberPage so my working code is @{ var teamMemberList = Model.TeamMembers.Cast(); foreach (var teamMember in teamMemberList) { @teamMember.DisplasyName } } Thanks for all the help
11 Views