Copied to clipboard

Flag this post as spam?

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


  • andrew shearer 513 posts 663 karma points
    Sep 07, 2021 @ 23:24
    andrew shearer
    0

    inject AssignedContentItem into partial view?

    Hi - I have a partial view to render an IPublishedElement model, but also need to show content from the current page (IPublishedContent). Can i obtain the current IPC from the DI container?

    this is what i tried but it doesn't work:

    @inject UmbracoHelper  UmbracoHelper
    @{
        var ipc = UmbracoHelper.AssignedContentItem;
    }
    

    thanks

  • andrew shearer 513 posts 663 karma points
    Sep 09, 2021 @ 02:06
    andrew shearer
    2

    so i managed to find this technique which seems to give me what im after:

    @inject IUmbracoContextAccessor umbracoContext
    
    @{
        var currentPage = umbracoContext.GetRequiredUmbracoContext().PublishedRequest.PublishedContent;
    }
    

    But still keen to hear thoughts on if this is an antipattern/bad practice and why, or if there is a better way.

    Thanks :D

  • 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