MVC and renderings

Current version: 10.3

Sitecore MVC uses a different set of controls than ASP.NET WebForms, and it therefore does not support all Sitecore renderings.

These two supported types of rendering are the most commonly used:

  • 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 mvc.getModel pipeline.

    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.

Note

The renderer classes in Sitecore MVC do not inherit from WebControl but from Renderer.

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:

  1. Right-click the Views folder in the Solution Explorer in Visual Studio, and select Add, New Item…

  2. Select Sitecore View Layout in the Siteccore/MVC group:

    Select a layout
  3. Sitecore Rocks will ask where to create the corresponding Sitecore definition item. Put the item in the Layouts folder in the master database:

    Select where to create item

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:

  1. Click the Layout folder in the content tree.

    Select the Layout folder
  2. Click MVC Layout to create the definition item:

    Create defition item
  3. Enter a name and click next. Place the item in the Layouts folder in Sitecore or a subfolder under Layouts:

    Select where to save item
  4. Create the layout you need (for example, an .aspx file) in the file system.

  5. Insert the path to the file you created in the Data.Path field of the new layout.

You create any of the renderings mentioned by clicking the Renderings folder in the content tree:

Create rendering

Do you have some feedback for us?

If you have suggestions for improving this article,