how to render MVC views from SurfaceController?

1.7k Views Asked by At

I have installed Umbraco 7 in MVC application. Have you achieved ever rendering MVC View from Surface Controller ? If it is possible to do how it can be done by passing model and passing a query string parameter to View ?

1

There are 1 best solutions below

0
Hywel Rees On BEST ANSWER

If I understand your question correctly, you need to use an approach called Route Hijacking, rather than surface controllers.

Simplified, the steps are:

  • Create a model matching a given Document Type.
  • Create a mapper to map an Umbraco IPublishedContent object to the model.
  • Create a controller that inherits Umbraco.Web.Mvc.RenderMvcController.
  • Override the Index action with a signature of ActionResult Index(Umbraco.Web.Models.RenderModel model).
  • Call the mapper, and return your view.

In your view / template, you will then be able to use

@model MyNewModel

instead of

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage

Here is a very good tutorial / explanation on the approach.

Be sure to read the follow up post too