Copied to clipboard

Flag this post as spam?

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


  • Johan 4 posts 84 karma points
    Feb 08, 2018 @ 13:50
    Johan
    0

    SurfaceController from class library is not found

    I've created a Visual Studio solution using the UaaS script according to https://our.umbraco.org/documentation/Umbraco-Cloud/Set-Up/Visual-Studio/.

    I have created a very simple SurfaceController in the *.Core project but when running the web site locally I get "The controller for path '/' was not found or does not implement IController" when accessing a view that uses the controller. It's caused by @{ Html.RenderAction("RenderHeader", "My"); }

    What have I missed?

    MyController.cs

    namespace CloudTest.Core.Controllers
    {
        class MyController: SurfaceController
        {
            public ActionResult RenderHeader()
            {
                return PartialView("~/Views/Partials/_Header.cshtml");
            }
        }
    }
    

    _Header.cshtml

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    <div>
        This is the header area!
    </div>
    

    Test.cshtml

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = null;
    }
    @{ Html.RenderAction("RenderHeader", "My"); }
    
  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Feb 08, 2018 @ 14:13
    Dave Woestenborghs
    102

    Hi Johan,

    You should make your class public. If you don't set a access modifier it will be private and can not be used in views

    public class MyController: SurfaceController
    
  • Johan 4 posts 84 karma points
    Feb 08, 2018 @ 14:27
    Johan
    0

    Thanks! That was it. Rookie misstake.

    Why aren't references to "umbraco.dll" and "Umbraco.Core.dll" added to the *Core class library project from the beginning?

Please Sign in or register to post replies

Write your reply to:

Draft