Ektron CMS ASP.NET MVC Sample

  • Updated

If you are looking for more information on how to implement an MVC application we have a sample below for your testing and convenience.

Ektron CMS ASP.NET MVC Sample

The Ektron MVC sample site is a lightweight version of the Ontrek site built to demonstrate how easy it is to build an MVC site on top of the Ektron .NET CMS.  In ASP.NET MVC, you still have access to all of our Framework APIs and these will allow you to quickly start building out your site.  Obviously ASP.NET Web Form based features like PageBuilder and our server controls won't work, but if you're building an MVC site, you're probably not concerned with server controls anyway.

The sample can be downloaded here:

MVC Sample Code

When you open the solution, you'll see a pretty basic ASP.NET MVC site with Controllers, Models, and View.  Let's take a quick look at the HomeController

mvckb001

If we look at the Home page, we'll see the how the properties of the ViewBag match up to sections of the home page

mvckb002

All we do is call into the Framework API,  get the content,  construct a view bag, and then bind the view bag to an MVC View:

mvckb003

Aliasing

The sample solution also has a custom MVC Routing Handler that can be used to route CMS aliases to the controllers you wish to handle them.

In the global.asax, you'll notice we register the AliasRouteHandler first.  This way, all urls will be checked for an alias before processing other routes.  If an alias isn't detected, it will fall through to the other registered routes.

mvckb004

If an alias is detected, AliasRouteHandler.ProcessRequest will be executed.  This code finds the corresponding Content Id for the url and sets the context RouteData.

mvckb005

You can configure which Controller and Action are routed to in the web.config:

mvckb006

Hopefully this quick overview helps everyone get the Ektron ASP.NET MVC sample up and running.  Once it's running, it's easy to step through and add new functionality.