Sitecore MVC Controller Rendering

Xing Liu • 11/13/2015

This blog post will describe the steps on how to create controller rendering in Sitecore MVC.  One of the benefits of using controller rendering is to set aside the complex logic in the MVC controller.

First, you need to create a definition item in the Sitecore tree.

Controller rendering

Fill in the following two fields with the controller name and the action name that you want to invoke.

Definition item

Once the definition item is created, you can create a corresponding Controller in the Controller s folder with the same action name stated in the definition item.

Below is an example of how you can invoke a form post action in the cshtml file.

@using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post))
        <div class="form-group">
        <input type="hidden" id="sitecoreitemid" name="sitecoreitemid" value="@idString" />
        <button type="submit" class="btn btn-primary">Submit</button>

Finally, make sure you include the following attribute on top of the action function.

public ActionResult ControllerAction(Guid sitecoreitemid)
//Controller Action

Xing Liu

Xing Liu is a Sitecore MVP with expertise in all aspects of ASP.NET and SQL Server development across a variety of industries including Government, Banking, Healthcare and Energy. He provides technical thought leadership and consulting to SymSoft and client development teams. Xing has deep expertise in using Sitecore Helix in an Agile delivery model to streamline the construction of complex Sitecore websites, portals and their associated authoring environments. Xing is also a globally recognized photographer with an Instagram following approaching 100,000.

Explore topics:

Other Blog Posts from Xing Liu