Introduction to working with Umbraco 6 and MVC

Regular MVC users would already be familiar with how MVC by default routes controllers and actions in this fashion. 

With Umbraco 6, the routes behave out of the box like this:

The other difference to standard MVC is normally your controller would inherit from 

System.Web.Mvc.Controller

But in Umbraco 6, your controller needs to inherit from

Umbraco.Web.Mvc.SurfaceController.

Suppose you want a friendly Url, while implementing your functionality with MVC. The following step are required:

  1. Create your controller with the class name – ‘ContactSurface’ and make sure it inherits from Umbraco.Web.Mvc.SurfaceController
  2. Add a ‘Display’ action and expect to receive the node “Id” as a parameter. In here you will probably need to use the nodeId to generate the model and return a partial view (note you can use the Umbraco ‘Node’ constructer to retrieve any node data defined in your doctype.)
  3. Use your model in the partial view to format all the content as usual.
  4. Create your node in umbraco eg. Contact Us at the route with the relevant ‘Doctype’ and a blank razor template.
  5. Open your razor template, and use the following code to invoke the controller and action

Html.RenderAction("Display", "ContactSurface", new { id = Node.GetCurrent().Id });

Now when you visit http://mydomain.com/Contact-Us , where your controller and action will be served while maintaining a friendly url.