Search code examples
asp.net-mvcasp.net-mvc-4model-view-controllerumbraco7umbraco6

Umbraco Surface Controller Not Routing Correctly


I have a bit of trouble getting a surface controller to fire correctly.

public class SocialShareSurfaceController : Umbraco.Web.Mvc.SurfaceController
{
    public ActionResult Index()
    {
        return Content("hello world");
    }
}

I'm trying to get to the controller via this URL: http://website.local/umbraco/surface/SocialShare/Index/

But I am getting 404 error..... If I then move this file to the App_Code folder go to the same URL I get this error

A route named 'umbraco-surface-SocialShareSurface' is already in the route collection. Route names must be unique. Parameter name: name

Any Ideas...


Solution

  • If you name your Surface Controller like you have above (including "Surface" in the name) then your route would need to also include Surface in the Controller name:

    http://website.local/umbraco/surface/SocialShareSurface/Index/
    

    You can just call your Surface Controller class SocialShareController - you don't need the Surface keyword in the class name at all.