Copied to clipboard

Flag this post as spam?

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


  • JJ 41 posts 83 karma points
    Mar 13, 2014 @ 13:58
    JJ
    0

    Partial CurrentPage is null

    I am reusing some code i've used a lot before in a current project and getting a null exception for CurrentPage

    The only difference in the project this is happening in is that I am using the Optimus package.

    Any ideas where to start troubleshooting please?

     

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        var root = Umbraco.Content(ViewData["node"]);
    }
    
    @if (root.Children.Where("Visible").Any())
    {
    <ul id="footerNav">
        @foreach (var childPage in root.Children.Where("Visible"))
        {
                <li @(childPage.IsAncestorOrSelf(@CurrentPage) ? "id=\"active\"" : null)>
                    <a href="@childPage.Url" title="@childPage.Name">@childPage.Name</a>
                </li>
        }
    </ul>
    }
    
    

     

    Called with 

    @Html.Partial("FooterMenu", new ViewDataDictionary { { "node", 3126 } })
  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 13, 2014 @ 15:10
    Jeroen Breuer
    0

    Hmm I'm not really used to dynamic code (I prefer Model.Content which is strongly typed), but I think it should work. The only thing I can find is that you have an @ before CurrentPage which is not allowed.

    Jeroen

  • JJ 41 posts 83 karma points
    Mar 13, 2014 @ 15:18
    JJ
    0

    Oops, yes left @ in when trying to troubleshoot. I get Object reference not set to an instance of an object when using Model.Content. 

    It's very odd, this works perfectly in the website I branched this solution from.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 13, 2014 @ 15:20
    Jeroen Breuer
    100

    It might be because it's a partial view. So just like you pass the node id in the ViewDataDictionary you could try the same for Model.Content or CurrentPage.

    Jeroen

  • JJ 41 posts 83 karma points
    Mar 13, 2014 @ 15:22
    JJ
    0

    I'll give that a go, thanks. As a note, if i dont send a ViewDataDictionary at all, it works fine (obviously setting an int for the root Id).

  • JJ 41 posts 83 karma points
    Mar 13, 2014 @ 15:26
    JJ
    0

    "So just like you pass the node id in the ViewDataDictionary you could try the same for Model.Content or CurrentPage."

    That worked, thank-you. Does ViewDataDictionary take over the Model for a partial then?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 13, 2014 @ 15:29
    Jeroen Breuer
    0

    The Model get's set in a Controller and when you're using a partial view it won't reach that controller so perhaps that's why it doesn't work. Glad you got it fixed like this. Please mark a post as the solution if it helped you.

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft