Copied to clipboard

Flag this post as spam?

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


  • Tom 117 posts 443 karma points
    Nov 24, 2016 @ 13:01
    Tom
    0

    Using CurrentPage og Model on a page without a node

    Hi, I'm not sure I'm able to make this understandable, but here we go!

    I have created a custom route to a page called 'course'. The view uses the same layout as the rest of the website, but no matching document/node is created in Umbraco.

    So, when I go to http://site.dk/course/index I just want the page to use CurrentPage and Model as if it was on the home node. But I want to show my custom view of course.

    Now I'm just getting alot of nullpointers because of the missing CurrentPage and Model.

    Any smart way to do this?

  • Alex Skrypnyk 5772 posts 21984 karma points MVP 4x admin c-trib
    Nov 24, 2016 @ 14:13
    Alex Skrypnyk
    0

    Hi Tom,

    You can use UmbracoHelper for getting Home page and use it like model for you view.

    Is it make sense for you?

    Thanks,

    Alex

  • Tom 117 posts 443 karma points
    Nov 25, 2016 @ 08:59
    Tom
    0

    I tried to make it work with an UmbracoVirtualNodeRouteHandler

       RouteTable.Routes.MapUmbracoRoute(
            "Course",
            "kurser/{action}/{Id}",
            new
            {
                controller = "Course",
                action = "Index",
                Id = UrlParameter.Optional
            },
            new haandbold.dk.Code.CourseVirtualNodeRouteHandler()
            );
    

    CourseVirtualNodeRouteHandler just returns my homepage node. But I still am missing the RenderModel, Any idea why?

  • Ali Kazai 11 posts 82 karma points c-trib
    Feb 20, 2020 @ 12:13
    Ali Kazai
    1

    I know this was asked a long long time ago in a galaxy far far away lol but its better late than never to add a fix for future developers.

    I have come across the same problem and found that using this command has fixed it.

    IPublishedContent CurrentPage = Umbraco.AssignedContentItem;
    
Please Sign in or register to post replies

Write your reply to:

Draft