Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Surface Controller or Custom Controller in Umbraco 7?

History

I'm a Web Forms developer with some .NET MVC experience, new to Umbraco and learning as I go.

So far I've been following the Umbraco documentation and videos to get set up which means all my controllers inherit from a "Controller Base" with common functions included, which in itself inherits from SurfaceController.

Recently however, I have noticed some bloggers and external reference material referencing RenderMvcController in the base class instead of SurfaceController - now the Umbraco documentation is unclear on the real differences between the two, nor which situations you should use them in.

The Question

Is there a clear and distinct difference between the imagined usage scenarios for a Surface Controller - inheriting from Umbraco.Web.Mvc.SurfaceController, and a Custom Controller - inheriting from Umbraco.Web.Mvc.RenderMvcController?

Thanks!

like image 589
Chris Wilson Avatar asked Sep 01 '14 10:09

Chris Wilson


People also ask

What is Umbraco surface controller?

A surface controller is an MVC controller that interacts with the front-end rendering of an Umbraco page. They can be used for rendering view components and for handling form data submissions. Surface controllers are auto-routed, meaning that you don't have to add/create your own routes for these controllers to work.

Does Umbraco use MVC?

Build advanced asp.net MVC applications on top of Umbraco. Take advantage of Umbraco's support for advanced routing, models, controllers and views.


2 Answers

The documentation for the SurfaceController is here: http://our.umbraco.org/documentation/Reference/Templating/Mvc/surface-controllers

In a nutshell, the SurfaceController is used for helping to interact with views. So for example you could post a form to a surface controller. Or you could write a child action to a view with a SurfaceController

RenderMvcController is used purely for routing to published pages. So you could sub-class RenderMvcController in order to 'hijack' requests to published pages of a specific Document Type. See here http://our.umbraco.org/documentation/Reference/Templating/Mvc/custom-controllers.

like image 140
Digbyswift Avatar answered Nov 03 '22 08:11

Digbyswift


To further clarify based on Digbyswift's answer:

SurfaceController = APIs or form targets (that then redirect)

RenderMvcController = custom logic to build a model or select a view for a content item (based on Document Type and, optionally, template)

like image 22
Richard Szalay Avatar answered Nov 03 '22 08:11

Richard Szalay