Last active
August 29, 2018 11:50
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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