TIHIDI: Implement a simple controller rendering in Sitecore MVC

This blog post will go through how I setup a basic Controller rendering using Glass Mapper Model.

Visit http://www.glass.lu/mapper/sc for more information on Glass Mapper for Sitecore.

TIHIDI: Stands for This Is How I Do It. I am going to write a series of blog posts going through how I do Sitecore related work. Hope it helps you!

We are going to use the same infrastructure as my previous post TIHIDI: Implement a simple view rendering in Sitecore MVC and Glass.

Keeping the model as is, we need to add the code to render this via a Controller Rendering. This functionality really does not need a controller rendering as we were able to do this in a view rendering but I wanted to give you an example.

Before we get into controllers, we need to setup a couple of things related to Glass and Business Logic.

I setup a ControllerSCContext similar to Nathanael Mann (the Mann). You can read about it further here. Why do I do it this way? I do not know, I was taught by the master(s) to do it this way. If there is a more efficient way to do it, please send me links.

Once that is done, I setup my business logic code.

I know the code is light but this shows you where the logic part of the code is supposed to be. I like my controllers as lean as possible. The next step is to define a controller.

We also need to register our new interfaces with Simple Injector.

Once that is done, its time to just copy our view rendering code since its going to be exactly the same. Create a new view under Views\Content.

Now that its all wired up, lets build and publish.

Setup a controller rendering in Sitecore to map this new controller.

Modify your item’s presentation to include this new rendering and fire it up.


If you have any questions or concerns, please get in touch with me. (@akshaysura13 on twitter or on Slack).


Add your comment

Your email address will not be published.