ASP.NET v4.5 MVC

You can return a Template Page in a classic ASP.NET MVC similar to ASP.NET Core MVC Controller except that in order to work around the lack of being able to async in classic ASP.NET MVC Action Results you need to return a task, but because we can replace the IOC Controller Factory in ASP.NET MVC you can use Constructor Injection to access the ITemplatePages dependency:

public class HomeController : Controller
{
    ITemplatePages pages;
    public HomeController(ITemplatePages pages) => this.pages = pages;

    public Task<MvcPageResult> Index() =>
        new PageResult(pages.GetPage("index")).ToMvcResultAsync();
}

ASP.NET MVC + Templates Demo

Checkout the ServiceStackApps/MvcTemplates repository for a stand-alone example, complete with a sidebar.html partial and a CustomTemplateFilters.cs.

This demo was created from the ServiceStack ASP.NET MVC5 Empty VS.NET Template.

made with by ServiceStack