SurfaceControllers in exported Packages

96 views
Skip to first unread message

bengr...@googlemail.com

unread,
Nov 3, 2015, 3:08:36 PM11/3/15
to Umbraco development
I am trying to create a package of my code in Umbraco 7. Everything works fine when I import the package to a new Umbraco project except that the new project can not find the SurfaceController in the routes table unless I specifically import the file into the Visual Studio project (which my end client won't have).

I've followed the instructions here: https://our.umbraco.org/documentation/reference/routing/surface-controllers

But get the same "Could not find route" error.

I've created an Area under my project called "Controls" and added the controller there. I've then adorned the controller with the [PluginController("Controls")]. So I have this structure:

--Root VS Project
--Area
--Controls
--Controllers
--MyController
I call this from my code like so:

@Html.Action("Index", "MyController", new { area = "Controls" }

This works absolutely fine again when running in VS with these files included as part of the project, but breaks when I then export this and import the package (with all of the other associated files) in to a new Umbraco project, saying that it can't find the route. My assumption was that adding the [PluginController("Controls")] attribute meant that upon startup the Umbraco project would find the controller and add it to the routes. Is this not the case?

Aaron Powell

unread,
Nov 3, 2015, 3:19:19 PM11/3/15
to umbra...@googlegroups.com
When using SurfaceController's from an external assembly they are treated a little differently, they are treated as Plugins and their folder structure is ~/App_Plugins/<Exported Name>/Views/<Controller>/<Action>.cshtml

So for your example the View would be:
~/App_Plugins/Controls/My/Index.cshtml

Also Umbraco cares about the 'Surface' part of a SurfaceController but MVC doesn't so if your controller is MySurfaceController then your "controller name" is MySurface, not My as if it was a "plain" controller of MyController.
--
You received this message because you are subscribed to the Google Groups "Umbraco development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to umbraco-dev...@googlegroups.com.
To post to this group, send email to umbra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/umbraco-dev/7667b816-af87-4372-adcb-4d4bc81c919a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

he...@sebastiaanjanssen.nl

unread,
Nov 3, 2015, 3:24:32 PM11/3/15
to Umbraco development
FYI: Umbraco hasn't cared about the Surface part as a naming convention for a long time now, it was unnecessary as they already inherited from SurfaceController (as opposed to inheriting from Controller).
So in your example: yes, MySurface would work but My would work just as well.

bengr...@googlemail.com

unread,
Nov 3, 2015, 3:42:24 PM11/3/15
to Umbraco development

Thanks Aaron.
Where do my controllers go then? The message makes it look like it's a problem with finding the controller, not the views themselves.

Error:
Additional information: No route in the route table matches the supplied values.

Aaron Powell

unread,
Nov 3, 2015, 4:55:06 PM11/3/15
to umbra...@googlegroups.com
That I didn't know, but it makes sense :)
To view this discussion on the web visit https://groups.google.com/d/msgid/umbraco-dev/46bf50e4-e32c-495d-8832-2ea318f20c97%40googlegroups.com.

bengr...@googlemail.com

unread,
Nov 4, 2015, 1:57:17 PM11/4/15
to Umbraco development

Hi Aaron - I'm still having no luck with this at all. Where would my controllers go? I get that the views need to be in the plugins folder, but I can't find a way of adding my SurfaceController to the project and having the routes registered.

Shannon Deminick

unread,
Nov 4, 2015, 3:39:18 PM11/4/15
to Umbraco development, bengr...@googlemail.com
All DLLs for your plugin need to end up in the /bin folder, just like all ASP.Net assemblies.If you are creating a plugin, then you need to build that to a DLL and ship it, plugins cannot just ship c# files.

bengr...@googlemail.com

unread,
Nov 5, 2015, 3:02:55 PM11/5/15
to Umbraco development, bengr...@googlemail.com
The problem was that I wasn't including the DLL of the porject I was exporting from.
Reply all
Reply to author
Forward
0 new messages