sxa-cshtml-controller-rendering

Converts .cshtml views into Sitecore SXA Controller Renderings with custom view paths.

Updated Jul 24, 2026
One-click install
npx skills add https://github.com/gweone/agent-plugins --skill sxa-cshtml-controller-rendering-gweone
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sxa-cshtml-controller-rendering
Source: https://github.com/gweone/agent-plugins/tree/main/plugin/sharpps-sitecore/skills/sxa-cshtml-controller-rendering
Command: npx skills add https://github.com/gweone/agent-plugins --skill sxa-cshtml-controller-rendering-gweone

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Sitecore SXA View Renderings fail outside the normal page-rendering pipeline (Web API controllers, background jobs) with an InvalidOperationException about an empty ViewContext stack. This Skill wires a .cshtml up as a Controller Rendering with a custom RenderingViewPath so it renders reliably from any context, without writing new controller code. ## Core Features & Use Cases - Controller Rendering setup: Reuses the existing Sitecore.XA.Foundation.Mvc.Controllers.StandardController with Controller Action Index and a RenderingViewPath field pointing at your .cshtml — no new C# required. - SPE-based template conversion: Converts an existing View Rendering item to the Controller Rendering template via Sitecore PowerShell Extensions, including the static TemplateManager.ChangeTemplate overload and the gotcha that the old Path value does not carry over to RenderingViewPath. - View location convention: Places the .cshtml under ~/Areas/$mvc_area$/Views/{FeatureName}/ so RenderingViewResolver can resolve the virtual path, with .csproj registration guidance. - Use Case: A search result variant rendered by SXA's Web API SearchController throws "Attempt to retrieve context object of type System.Web.Mvc.ViewContext from empty stack" — convert its View Rendering item to a Controller Rendering pointing at the same .cshtml and it renders immediately. ## Quick Start Convert my existing SXA View Rendering item at /sitecore/content/.../SearchResultVariant into a Controller Rendering that uses the .cshtml at /Areas/v1/Views/Search/SearchResultVariant.cshtml.

Frequently Asked Questions about sxa-cshtml-controller-rendering

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make a .cshtml work as a Sitecore SXA Controller Rendering?

Create a Controller Rendering item and set Controller to Sitecore.XA.Foundation.Mvc.Controllers.StandardController, Controller Action to Index, and RenderingViewPath to your .cshtml path. The StandardController ships with SXA, so no new controller code is needed.

Why does my Sitecore View Rendering fail with ViewContext empty stack error?

View Renderings require an active System.Web.Mvc.ViewContext that Sitecore only pushes during the normal page-rendering pipeline. Rendering from a Web API controller, background job, or custom pipeline never establishes it, causing the InvalidOperationException.

How do I convert a View Rendering item to Controller Rendering with SPE?

Use the static TemplateManager.ChangeTemplate($item, $changes) overload in Sitecore PowerShell Extensions, not the instance method. Capture the old Path field value first, because it does not carry over to the RenderingViewPath field automatically.

What is the difference between RenderingViewPath and Path fields in Sitecore?

RenderingViewPath belongs to the Controller Rendering template while Path belongs to the View Rendering template; they are separate fields with different IDs. ChangeTemplate matches fields by ID, so the Path value silently stays blank on the new template.

Where should the .cshtml file be located for a Controller Rendering?

Place it under ~/Areas/$mvc_area$/Views/{FeatureName}/{RenderingName}.cshtml in the Feature project. RenderingViewResolver checks the virtual path with VirtualPathChecker.FileExists, so files outside the Area's folder structure will not resolve.

When should I use a Controller Rendering instead of a View Rendering in SXA?

Use a Controller Rendering whenever the rendering must execute outside a normal page request, such as from a Web API controller or background job. If the rendering only runs inside the standard page pipeline, a plain View Rendering is sufficient.