UmbracoHelper Help = new UmbracoHelper(UmbracoContext.Current); IEnumerable Item = Help.TypedContent(JsonId.ToString().Split(',')).OfType();
Why are there 2 different ways to search with different return values? I think there is a difference because the first one is the node and the second the content but i don't understand why there are 2 objects for that?
And i try to do everything strong typed so i don't want to use dynamic or var of something like that.
Can please tell me what is the best way to search?
The IPublishedContent is new since 4.10 and used in MVC. The DynamicNode is added in 4.7 and for the old Razor macro's. You can use both, but I prefer to use IPublishedContent because I'm using MVC in my websites and it's easier to get there.
I already found that page but i always get a dynamicnode and not a IEnumerable<IPublishedContent>, i do everthing with hijacking routes do i need something else for DynamicNode BlogRoot = new DynamicNode(Model.Content.Id);?
DynamicNode vs IPublishedContent
I'm kinda confused about how to get the content from a item. I search for a itemlist like this:
DynamicNode BlogRoot = new DynamicNode(Model.Content.Id);
IEnumerable Blogs = BlogRoot.Descendants("BlogDetail").Where(x => x.Visible);
or sometimes like this
UmbracoHelper Help = new UmbracoHelper(UmbracoContext.Current);
IEnumerable Item = Help.TypedContent(JsonId.ToString().Split(',')).OfType();
Why are there 2 different ways to search with different return values? I think there is a difference because the first one is the node and the second the content but i don't understand why there are 2 objects for that?
And i try to do everything strong typed so i don't want to use dynamic or var of something like that.
Can please tell me what is the best way to search?
I got now this as a solution but is it the right one?
IPublishedContent Author = Helper.GetRelatedItem(BlogItem.GetProperty("lid").Value);
the BlogItem is a DynamicNode..
The IPublishedContent is new since 4.10 and used in MVC. The DynamicNode is added in 4.7 and for the old Razor macro's. You can use both, but I prefer to use IPublishedContent because I'm using MVC in my websites and it's easier to get there.
Jeroen
Thanks Jeroen, but how do i query in such way that i get IPublishedContent back?
You can find more info here: http://our.umbraco.org/Documentation/Reference/Mvc/querying. You can't use the DynamicNode and IPublishedContent together. It's better to only use IPublishedContent and also query with that.
Jeroen
I already found that page but i always get a dynamicnode and not a IEnumerable<IPublishedContent>, i do everthing with hijacking routes do i need something else for DynamicNode BlogRoot = new DynamicNode(Model.Content.Id);?
Yes don't use the DynamicNode. Go for the second example you posted because that is IPublishedContent.
The querying should work on that.
Jeroen
Thank Jeroen!
imo the dynamic methods should be decorated with obsolete so people are prompted to stop using them when writing new code.
I Agree. I think Shannon even wants to remove it completely from future versions.
Jeroen
is working on a reply...