Copied to clipboard

Flag this post as spam?

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


  • Maff 141 posts 466 karma points
    Jan 13, 2015 @ 13:23
    Maff
    0

    Umbraco.TypedContent() becomes dynamic (and stops working!) when rendering a page

    Hi,

    Not sure if this is a bug or just the way I'm implementing it, but I am seeing inconsistent behaviour with Umbraco.TypedContent() when rendering partial pages.

    I render a page using the following code:

    @RenderPage(string.Format("~/Views/{0}.cshtml", myPage.Template.Alias), myPage.Id)

    and on the partial I have the following code (which doesn't work):

    var nodeId = PageData[0];
    var contentNode = Umbraco.TypedContent(nodeId);

    According to Visual Studio, the TypedContent() method is a Dynamic call, and subsequent methods like @contentNode.GetPropertyValue("section") give an error!

    If I change the code on my partial to the below, the TypedContent() method is correctly recognised as an  IPublishedContent type, and subsequent methods work fine:

    var nodeId = 0;
    nodeId = PageData[0];
    var contentNode = Umbraco.TypedContent(nodeId);

     

    Does anyone know why this is happening? In both cases I am passing the same value (an int) into the method, just declaring the int variable locally in the version that works?! :s

    Cheers,

    Maff

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jan 13, 2015 @ 13:49
    Jeavon Leopold
    100

    Hi Maff,

    PageData[0] is dynamic, if you are 100% sure it's a int, cast it. e.g.

    var nodeId = (int)PageData[0];
    

    Jeavon

  • Maff 141 posts 466 karma points
    Jan 13, 2015 @ 14:33
    Maff
    0

    Yes that does the trick - thanks Jeavon :)

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jan 13, 2015 @ 17:41
    Jeavon Leopold
    0

    Cool :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies