Copied to clipboard

Flag this post as spam?

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


  • Ben 6 posts 96 karma points
    Aug 06, 2018 @ 09:13
    Ben
    0

    Best way to get current page info in partial view

    Hi,

    I have a partial view with a custom model and was wondering which of the following ways is the most efficient way of getting the current page information:

    1. Make my custom model inherit the 'RenderModel'
    2. Use UmbracoContext directly in the partial to get node with Umbraco.TypedContent

    Thanks in advance for your help.

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Aug 07, 2018 @ 19:08
    Marc Goodson
    102

    Hi Ben

    If you make your partial view inherit UmbracoViewPage + your custom model in the following way

    @inherits UmbracoViewPage

    Then you'll have access to all the usual Umbraco Helper methods via @Umbraco in your partial view, and also, therefore, the currently assigned content page!:

    var currentPage = Umbraco.AssignedContentItem;

    If that is what you are after?

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft