Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Edwin van Koppen 156 posts 270 karma points
    Feb 28, 2013 @ 14:50
    Edwin van Koppen
    0

    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?

  • Edwin van Koppen 156 posts 270 karma points
    Feb 28, 2013 @ 15:05
    Edwin van Koppen
    0

    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..

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 28, 2013 @ 15:13
    Jeroen Breuer
    0

    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

  • Edwin van Koppen 156 posts 270 karma points
    Feb 28, 2013 @ 15:29
    Edwin van Koppen
    0

    Thanks Jeroen, but how do i query in such way that i get IPublishedContent back?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 28, 2013 @ 15:34
    Jeroen Breuer
    0

    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

  • Edwin van Koppen 156 posts 270 karma points
    Feb 28, 2013 @ 15:39
    Edwin van Koppen
    0

    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);?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Feb 28, 2013 @ 15:43
    Jeroen Breuer
    101

    Yes don't use the DynamicNode. Go for the second example you posted because that is IPublishedContent.

    UmbracoHelper Help = new UmbracoHelper(UmbracoContext.Current);
    IEnumerable Item = Help.TypedContent(JsonId.ToString().Split(',')).OfType();

    The querying should work on that.

    Jeroen

  • Edwin van Koppen 156 posts 270 karma points
    Feb 28, 2013 @ 15:44
    Edwin van Koppen
    0

    Thank Jeroen!

  • andrew shearer 510 posts 659 karma points
    Aug 17, 2013 @ 04:57
    andrew shearer
    0

     

    imo the dynamic methods should be decorated with obsolete so people are prompted to stop using them when writing new code.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Aug 20, 2013 @ 12:09
    Jeroen Breuer
    0

    I Agree. I think Shannon even wants to remove it completely from future versions.

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft