Umbraco 6 – Controller Hijacking or Custom Controllers
Umbraco 6 now has pretty extensive MVC 4 support; enabling you to essentially bolt in this excellent data manager (cms) , getting you up and running very very quickly.
One thing I love about .net MVC is the strongly typed views. Strongly typing views opens the doors to a series of other awesome features within the mvc framework that become particularly when it comes to templating and creating large amounts of view logic however that’s a separate blog….
Umbraco 6 allows you to hijack the controller engine of MVC and leverage the Umbraco data context. It’s super simple..
Okay, its all about naming convention straight off the bat; the documentation Umbraco provide a quite helpful also however I’ll show you how I’ve simplified it slightly:
Create a doctype
Create a controller with the same name i.e NewsController
Inherit the MVC render controller base class Umbraco.Web.Mvc.RenderMvcController
Ensure your params contain the IPublishedContent Wrapper RenderModel
Now the RenderModel will contain he umbraco context of the requested url so this means you can simply do whatever you’d like with the data, render to whichever view map to whichever view model..etc etc.
Powerful stuff.