Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
What is the best way to get values from other nodes in Umbraco? I want to use this to query general settings on my website. I have a dedicated node in my content tree where all settings are. I've tried using this:
var settings = Umbraco.Content(2017)
This returns an "Umbraco.Web.PublishedModels.Homepage" object as expected. When I want to pick some values from this model, it won't let me. For example, I want to do this:
This returns an error stating "'IPublishedContent' does not contain a definition for 'WebsiteName'". It does work when I add the Value method:
This works for a textbox field, but not for other properties like nested content or a link property.
Does anyone know how to correctly query these properties as well? Thanks in advance!
Are you using Models Builder?
A property of type "nestedcontent" will return a list of nodes, which you will need to iterate through.
Read through the relevant Umbraco documention to see how each property is returned, and how best to handle.
Thanks for your answer. Yes, I think we are using the Models Builder, our configuration looks like this:
Though I can't use the Models Builder like I would in let's say a partial view (Model.WebsiteName e.g.). It returns an: "'IPublishedContent' does not contain a definition for 'WebsiteName'".
I've both tried it on my master template and in a partial view, both result in these errors.
Try something like
var settings = Umbraco.TypedContent(2017).OfType<HomePage>();
I think the "content" method just returns a dynamic type.
The "P" on HomePage might not be captilized in your project - Depends how you spelt "homepage" or "home page" :)
You could do this as well, which might be more efficient, and doesnt rely on hardcoding the ID
var settings = Model.Site().OfType<HomePage>();
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted