Matthew Proctor
Matthew Proctor

Reputation: 53

Why do I keep seeing Umbraco.Web.PublishedModels and Umbraco.Web.Models?

I am new to Umbraco, can anyone tell me why I am seeing these 2 values instead of the expected string?

I get Umbraco.Web.Models when I use this code to get a link

var businessLink = child.Value("websiteLink");

And Umbraco.Web.PublishedModels when trying to use this code to get the name of the previous child to my current node:

var business = child.AncestorsOrSelf("Business").Last();

Any advice would be greatly appreciated.

Upvotes: 0

Views: 232

Answers (1)

Nurhak Kaya
Nurhak Kaya

Reputation: 1781

I'm not sure what you're trying to accomplish, but for Umbraco v8, all of the following extension methods are available on Umbraco.Core.Models.IPublishedContent so you can have strongly typed access to all of them with intellisense for both content and media. These methods return IEnumerable<IPublishedContent>.

Children() // this is the same as using the Children property on the content item.
Ancestors()
Ancestors(int level)
Ancestors(string nodeTypeAlias)
AncestorsOrSelf()
AncestorsOrSelf(int level)
AncestorsOrSelf(string nodeTypeAlias)
Descendants()
Descendants(int level)
Descendants(string nodeTypeAlias)
DescendantsOrSelf()
DescendantsOrSelf(int level)
DescendantsOrSelf(string nodeTypeAlias)
Siblings()
SiblingsAndSelf()

Alternatively, you have other methods that return a single IPublishedContent.

Ancestor()
AncestorOrSelf()
AncestorOrSelf(int level)
AncestorOrSelf(string nodeTypeAlias)
AncestorOrSelf(Func<IPublishedContent, bool> func)

More information can be found here: https://our.umbraco.com/documentation/Reference/Templating/Mvc/querying

Upvotes: 0

Related Questions