Copied to clipboard

Flag this post as spam?

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


  • Carsten 3 posts 23 karma points
    Aug 28, 2014 @ 11:26
    Carsten
    0

    Get node from a SurfaceController?

    Hi

    I’ve got a clean asp.net mvc website that I would like to move to Umbraco. I thought that it would be easy – just add some routing, inherit from SurfaceController and bam...that’s it.

    All views render as expected but I can’t get nodes from Umbraco from my SurfaceController. Can it be because I’m using custom routing?

    So here's what I got.

    First I added custom routing to Umbraco:

    public class StartupHandler : Umbraco.Core.IApplicationEventHandler
    {
        public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            RouteTable.Routes.MapRoute(
                "recipe",
                "recipe/{action}/{url}",
                new
                {
                    controller = "Recipe",
                    action = "Index",
                    url = UrlParameter.Optional
                });
        }
    
        public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
        }
    
        public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
        }
    }
    

    Then I changed my controllers to inherit from SurfaceController:

    public class RecipeController : Umbraco.Web.Mvc.SurfaceController
    {
        public RecipeController() : this(UmbracoContext.Current)
        {
        }
    
        public RecipeController(UmbracoContext umbracoContext) : base(umbracoContext)
        {
        }
    }
    

    Even though I got the UmbracoContext I can’t get any nodes. All return null. Any ideas?

    Umbraco version 7.15

Please Sign in or register to post replies

Write your reply to:

Draft