Creating a Controller Rendering in Sitecore: A Step-by-Step Guide

A Controller Rendering helps to connect Sitecore with external systems or custom logic by allowing developers to write code in C# that generates HTML content for webpages. It helps to customize and extend the functionality of Sitecore-powered websites. Controller rendering creation can be achieved by following these steps:

Step 1. Create a .cshtml file for Layout like this DemoLayout.cshtml


Step 2. Create a template like this 'DemoTemplateforVeiwRendering' with fields Title, ProjectName, ImageName, Image, Json, and URL

Step 3. Create Content like this Demo using the template 'DemoTemplateforVeiwRendering'

Step 4. Add layout in content Demo- Present->details->Edit->Layout-> Add DemoLayout (which is created point 1)

Step 5. Create another .cshtml in the Views folder for controller rendering like this DemoControllerRendering.cshtml

Step 6. Create DemoController.cs file like

Step 7. Create DemoViewModel.cs file like

Step 8. Create a Controller rendering like this DemoControllerRendering with–

Controller - Sitecore.DemoProject.MVC.Web.Controller.DemoController, Sitecore.DemoProject.MVC.Web

Controller Action – DemoControllerRendering

Step 9. Add control in content Demo- Present->details->Edit->Controls->Add rendering with placeholder

Step 10. Save, Publish Item and Preview

Output




要查看或添加评论,请登录

Praveen Dubey的更多文章

社区洞察

其他会员也浏览了