Get Templates to work with razor rendering api integration


Can I use [ClientCanSwapTemplates] and [DefaultView("MyView")] with the new Templates system ?

I could not wire it up.

I used Templates for api and ServiceGateway but it’s too much for what I’m trying to achieve : nice html over json …

Many thanks,

We only just added initial support for using TemplatePages View Pages to render the HTML for Service Responses in this current release. It works similarly to Razor ViewPages where it uses first matching View Page where the Response DTO is injected as the Model property.

You can find tests on dynamically specifying the View and Template in TemplateViewPagesTests.

The View Pages can be in any folder in the /Views folder with the format {PageName}.html where PageName can be either the Request DTO Name, Response DTO Name or HttpResult.View property if returning a custom HttpResult. All page names need to be unique in the /Views folder.

One difference from Razor is that it uses a cascading _layout.html instead of /Views/Shared/_Layout.cshtml. So if your view page was in:


It will use the closest _layout.html it can find starting from:


This is now available from ServiceStack v5 that’s now available on MyGet.