Skip to content

Instantly share code, notes, and snippets.

@jrunestone
Last active August 29, 2018 11:50
Show Gist options
  • Save jrunestone/22499cd4c2a83d004c4700d6f35be7df to your computer and use it in GitHub Desktop.
Save jrunestone/22499cd4c2a83d004c4700d6f35be7df to your computer and use it in GitHub Desktop.
A generic Episerver page controller with a default view model with generic types
public class DefaultPageController : PageControllerBase<PageTypeBase>
{
public DefaultPageController(IContentRepository contentRepository) : base(contentRepository)
{
}
public ActionResult Index(PageTypeBase currentPage)
{
Type origType = currentPage.GetOriginalType();
Type vmType = typeof(DefaultPageViewModel<>).MakeGenericType(origType);
var vm = Activator.CreateInstance(vmType, currentPage);
return View($"~/Views/Pages/{origType.Name}/Index.cshtml", vm);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment