A Better Kentico 12 MVC Boilerplate

Trevor Fayas / May 28, 2019
A Better Kentico 12 MVC Boilerplate
The transition from Portal Method to MVC can be challenging for many who are new to MVC.  Many of the features we were accustomed to having through webparts now require coding to enable or add them in.  Kentico provided the Dancing Goat site in MVC to showcase many of their features, but the down side is there's too much in it, it's very hard to "strip" out the Dancing Goat and preserve the Kentico features so you can start a new project.

On the other hand, the "Blank MVC Site" goes to the other extreme, it's truly blank.  There's nothing in it: no Authentication OWIN setup, no routes or helpers, no 404s handlers, no bundles, no nothing.  It requires a first-time developer to go through a lot of documentation to get things started.

A Better Boilerplate

I've slowly build a base set of tools to create a Kentico 12 MVC Boilerplate project on GitHub.  The reason for putting it on GitHub is because I really wanted this boilerplate to be a community project, where people can contribute things like useful helpers, examples, and much needed Inline Editors, Widgets, Sections, and more.  
Please use the Contact Form below for a link to the Boilerplate. From there, I encourage you to submit a pull request to add contributions. 


The installation steps are on the Repo's main page, and although there probably won't be a large number of database changes, Kentico Continuous Integration is leveraged so you can do a CI-Restore once you have the base database installed and hooked up in order to get any changes that occurred since the initial push.  I have included a powershell and a bash file that makes this easy, just requiring you to add in the path to the installation and your IIS app pool name. 

You can also leverage the .gitignore file and setup of the web.config to better handle putting your Kentico projects into your own GIT repo, such as Azure Dev Ops.

Current Features

The boilerplate comes with the following App_Start features enabled:
  • Page Builder Enablement
  • jQuery, jQuery Validate and jQuery Ajax Unobtrusive bundles (used in Client-Side form validation and Ajax simplification)
  • OWIN Authentication for Kentico setup
  • Routes with the Kentico required route, Dynamic routing for NodeAliasPath routing, normal Routing and 404 handler.
Bootstrap and jQuery
The instance includes Bootstrap 4 CSS and Javascript and jQuery (including the Kentico libraries needed to run the Page Builder).

I've included some Helper classes, including a sample BaseController with a SetContext(DocumentID) method that allows you to add CurrentDocument, CurrentCulture, CurrentSite properties in the ViewBag.
  • DocumentQueryHelper is a class that mimics the Repeater/Hierarchy Repeater, allowing you to easily retrieve TreeNodes.  Caching is automatically handled for you.  It also has a helper to find Nodes based on the NodeAliasPath (checking Aliases as well).
  • DataQueryHelper mimics the Repeater with Custom Query, allowing you to use CMS Queries and get the data back, again Caching is handled and Query Parameters supported.
  • EnvironmentHelper grants access to things such as the AuthenticatedUser, if Preview is Enabled, etc.  KMVC Route class which is used in route handling based on the URL instead of hard set paths.
Sample Widgets, Section, and Inline Editor
I've included a 'bare bone' set of widgets, sections, and Inline editors.  Little more than an input and an output for the widgets, these are great to clone and create your own.  They show both a widget using an Inline Editor, and one using the dialog screen.  Same for the Section and Inline Editor.  I do plan on importing the Inline Editors that come with the Dancing Goat site eventually.

Master Page, Home Page, Login
I've included a Bare-Bones Master Page (Shared Layout), Home Page, and Login Control/Action/Views.  These don't have any fluff, just the bare minimum to have Kentico's features enabled, and Bootstrap and jQuery included since these are often needed for the example pages.  The login page provides a very basic Login screen and is properly hooked up into Kentico's OWIN authentication.

There is an Examples Controller and Pages that show you how to mimic "Web Parts" in a couple different ways.  One uses the Model View-View Model approach, one uses pure context (ViewBag), one uses more of a Property type of approach.  This should help you start out!  Feel free to modify the Examples Controller and put in your own Actions and Views for useful example situations for others to benefit from.

Relationships Extended
I've included my Relationships Extended module in the Kentico CMS portion of the site, and the Relationships Extended MVC Helper in the MVC Project.  Keep in mind if you don't want these, just remove the nuget packages.


As always, I am always open to feedback and suggestions. Please don't hesitate to reach out! 
Trevor Fayas
About the Author

Trevor Fayas
Senior Software Engineer I

Trevor Fayas is a Senior Software Engineer I at Heartland Business Systems and a Kentico MVP. He is ranked in the top 10 Kentico Developer Network Q&A Contributors, and has published multiple tools on the Kentico Marketplace.  Trevor’s passion is to help build and equip Kentico users and developers with the tools to really take their site to the next level.

Blog post currently doesn't have any comments.