Copied to clipboard

Flag this post as spam?

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


  • Ault Nathanielsz 87 posts 407 karma points c-trib
    Oct 01, 2020 @ 15:48
    Ault Nathanielsz
    0

    html.renderPartial ... from IPublishedElement to IPublishedContent

    I am using the new BlockList to add layout elements to a node. (Inside each layout is another Blocklist which allows users to add blocks of content to the layout area.)

    I call the layouts thusly:

        var varBlocks = Model.WContent12;
    foreach (var varBlock in varBlocks)
    {
        var varBlockContent = varBlock.Content;
        var varBlockSettings = varBlock.Settings;
        string strPartial = "features/" + varBlockContent.ContentType.Alias;
        @Html.Partial(strPartial, varBlockContent);
    }
    

    So far, so good.

    However, in one particular layout, I wish to add a left navigation automatically. I have done this in other websites and intend to reuse the code. I would normally just use @Html.renderPartial("leftnav") and all would be good.

    Except that at this point I am calling the partial from inside the BlockList element. That means I am trying to call IPublishedContent from IPublishedElement.

    If I just use the straight renderPartial I get a Cannot bind source type Umbraco.Core.Models.etc... error

    I therefore need a method for referring back to the model that called the element, and passing that through in the partial call. Something like: @Html.renderPartial("leftnav", doctypeThatCalledThisElement)

    I remember something along these lines using nested content, but it is buried in the codes of time. Any ideas?

  • Ault Nathanielsz 87 posts 407 karma points c-trib
    Oct 01, 2020 @ 16:17
    Ault Nathanielsz
    100

    In case anyone else is in this pickle the way out is: Umbraco.AssignedContentItem - this will give you the model of the node that is calling the blocklist element.

    as in:

    Html.RenderPartial("leftnav", Umbraco.AssignedContentItem)

Please Sign in or register to post replies

Write your reply to:

Draft