Run Razor view from API

Note most of ServiceStack.Razor features are documented on the Razor Rockstars website: http://razor.servicestack.net which includes info on how to register the RazorFormat plugin and where your Razor Views can be placed.

ServiceStack is who typically renders the Razor View which it does using the Response for your Service as the View Model into your Razor View and rendering the HTML output to the HTTP Response Stream.

But you can render a Razor View to a string using the RazorFormat by getting your view page and rendering it using your view model with:

var razor = HostContext.GetPlugin<RazorFormat>();
var razorView = razor.GetViewPage("MyView"); //e.g. /Views/MyView.cshtml
var html = razor.RenderToHtml(razorView , dto);