Copied to clipboard

Flag this post as spam?

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


  • Jason Berkan 7 posts 58 karma points
    Jun 05, 2013 @ 22:45
    Jason Berkan
    0

    How do I access the root node from a surface controller called from outside of Umbraco?

    I have created a surface controller that takes the CurrentPage and uses that to find the root node of the tree and from there, creates a PartialView menu of the entire site.

    I need to be able to call this surface controller from a separate MVC area that is outside of the Umbraco pipeline.  Inside the surface controller, how would I access the root node?

  • Jason Berkan 7 posts 58 karma points
    Jun 06, 2013 @ 18:48
    Jason Berkan
    101

    The following code works in a Surface Controller in v6 of Umbraco.  It obtains the root node and then instantiates a new RenderModel with that information, before passing that off to the PartialView.

        public class PageSurfaceController : SurfaceController
        {
            [ChildActionOnly]
            public PartialViewResult Menu()
            {
                IPublishedContent root = Umbraco.TypedContentAtRoot().First();
                RenderModel model = new RenderModel(root, new CultureInfo("en-US"));
                return PartialView(model);
            }
        }
Please Sign in or register to post replies

Write your reply to:

Draft