MVC and renderings
Discusses view renderings in MVC.
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:
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.
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:
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:
This rendering type outputs the return value of a call to a static method.
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.
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:
Create the layout you need (for example, an
.aspxfile) in the file system.
Insert the path to the file you created in the
Data.Pathfield of the new layout.
You create any of the renderings mentioned by clicking the Renderings folder in the content tree: