These two supported types of rendering are the most commonly:
- View Rendering
This rendering type is a Razor view. Sitecore provides a default controller and model for the view. You can customize the model by changing the
Use this when you want to render item content that does not require any significant business or presentation logic.
- Controller Rendering
For this rendering type, you supply controller, model and view. You specify in the rendering definition item what action Sitecore takes to render the component.
Use this to render content that relies on external data and/or requires significant business or presentation logic.
This rendering is used occasionally:
- Item Rendering
This rendering type requests that content (an item) renders itself. The content has information about how it renders.
The following renderings are supported for legacy reasons:
- Method Rendering
This rendering type outputs the return value of a call to a static method.
- XSLT Rendering
Use this to render Sitecore XSLT on a Sitecore MVC page. This rendering type is similar to the View Rendering type, but using XSLT as the template engine instead of Razor.
Use this if you have a library of existing Sitecore XSLT components that you do not want to rewrite.
- Url Rendering
This rendering type renders the response of a HTTP GET request onto the current page.
You can use it if you need to screen scrape HTML from another system. Can sometimes be used to avoid using iframes.
The renderer classes in Sitecore MVC do not inherit from
WebControl but from
Adding layouts and renderings to an MVC solution
You can add MVC layouts and renderings to an MVC solution in two ways: either from Sitecore Rocks or from the Content Editor.
To add an MVC layout from Sitecore Rocks:
- Right-click the Views folder in the Solution Explorer in Visual Studio, and select Add, New Item…
- Select Sitecore View Layout in the Siteccore/MVC group:
- Sitecore Rocks will ask where to create the corresponding Sitecore definition item. Put the item in the Layouts folder in the master database:
You create renderings in the same way:
- Choose Sitecore View Rendering to create a View Rendering, and put the definition item in Renderings.
- Choose Sitecore Controller Rendering to create a Controller Rendering, and put the definition item in Renderings.
To add an MVC layout from the Sitecore Content Editor:
- Click the Layout folder in the content tree.
- Click MVC Layout to create the definition item:
- Enter a name and click next. Place the item in the Layouts folder in Sitecore or a subfolder under Layouts:
- Sitecore generates the cshtml file that corresponds to the definition item. Place it in the Views folder of your Visual Studio project:
Note that Sitecore places the file in the webroot file structure - not in your Visual Studio project structure.
You create any of the renderings mentioned by clicking the Renderings folder in the content tree: