Question

Just playing around with Sitecore 7 and MVC, and I try to get the rendering basics working.

So far, I have been able to create a View Rendering (and mapped to the relevant .cshtml file) within the Renderings section, and applied these to the presentation details of the item (in much the same way you do with ASPX Layouts/ASCX Sublayouts).

I have also been able to map the Item to a controller (using the Controller and Action fields on the item), have the Index action on the controller (inherited from SitecoreController) return the view ~/Views/Home/Index.

The issue I can't seem to wrap my head around is merging the two rendering methods. I want to be able to create controllers that map to an Item, but render the item using the ViewRenderer, rather than using the default MVC conventing of return View(), so that I can:

  1. Specify the location of the view files within a multi-site environment by setting the path parameter of the rendering; and
  2. Have content authors/managers manage the renderings the way that the Layout/Sublayout does with place holders.

Does anyone know of a way that this can be achieved?

Was it helpful?

Solution

Have you taken a look at Controller Renderings in Sitecore MVC? These give you the ability to map a controller class to a Sitecore presentation item that can be statically or dynamically bound to your layout details.

This post has a reasonable overview of how to get started with controller renderings.

As for specifying the location of View files for multi-site environments you can pass the path to the razor file into the Controller View method, for example:

return View("~/Areas/SampleArea/Views/SampleArea/Index.cshtml");

I hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top