Controllers - JimBobSquarePants/Zoombraco GitHub Wiki
Zoombraco comes with two base controllers. ZoombracoController
and `ZoombracoApiController. All controllers should inherit from these classes.
The classification of these types is as follows:
-
ZoombracoApiController
The base controller for all render and surface controllers. -
ZoombracoController
The base controller for all WebApi controllers.
The ZoombracoApiController
inherits the UmbracoApiController
class adding an extra property ContentHelper
that allows context-aware, strong-typed, traversal of the the document tree.
The ZoombracoController
is an amalgam of the RenderMvcController
and SurfaceController
classes with several significant extras.
Firstly the class contains an extra property ContentHelper
that allows context-aware, strong-typed, traversal of the the document tree. Additionally the class contains the following methods:
RenderViewToString(string viewName, object model)
RenderPartialToString(string viewName, object model)
These methods allow the templated result of an action as a string. Useful in returning content via Ajax.
Here's an example of using a controller to return our Generic
class.
/// <summary>
/// The Generic page controller
/// </summary>
[UmbracoOutputCache]
public class GenericController : ZoombracoController
{
/// <inheritdoc />
public override ActionResult Index(RenderModel model)
{
Generic generic = model.As<Generic>();
RenderPage<Generic> viewModel = new RenderPage<Generic>(generic);
return this.CurrentTemplate(viewModel);
}
}