EPiServer Default Controller to avoid dummy controllers

EPiServer MVC site often have controllers that do not have any logic and so they shouldn't even exist. EPiServer have done great job to allow inheritance and covariance in controller selection. So you can set up your default controller which is used when you haven't created explicitly controller. Here's a simply default controller which do the job.

namespace Huilaaja.Net.Controllers
{
    [TemplateDescriptor(Inherited = true)]
    public class DefaultPageController : PageController
    {
        public ViewResult Index(SitePageData currentPage)
        {
            var model = CreateModel(currentPage);
            return View(string.Format("~/Views/Pages/{0}.cshtml", currentPage.GetOriginalType().Name), model);
        }

        private static IPageViewModel CreateModel(SitePageData page)
        {
            Type viewModelType = typeof(PageViewModel<>).MakeGenericType(page.GetOriginalType());
            return (IPageViewModel) Activator.CreateInstance(viewModelType, page);
        }
    }
}
  It's also required to create some sort of interface for the generic view model.

namespace Huilaaja.Net.ViewModels
{
    public interface IPageViewModel where T : SitePageData
    {
        LayoutViewModel Layout { get; }
        T Page { get; }
    }
}
EPiServer MVC site often have controllers that do not have any logic and so they shouldn't even exis…