您可以通过添加所需的config sections to your Web.config剃刀添加到现有ServiceStack Web应用程序:
<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false"/>
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false"/>
</sectionGroup>
</configSections>
<appSettings>
<add key="webPages:Enabled" value="false" />
</appSettings>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<pages pageBaseType="ServiceStack.Razor.ViewPage">
<namespaces>
<add namespace="System" />
<add namespace="System.Linq" />
<add namespace="ServiceStack" />
<add namespace="ServiceStack.Html" />
<add namespace="ServiceStack.Razor" />
<add namespace="ServiceStack.Text" />
<add namespace="ServiceStack.OrmLite" />
<add namespace="ProjectNamespace" />
<add namespace="ProjectNamespace.ServiceModel" />
</namespaces>
</pages>
</system.web.webPages.razor>
</configuration>
然后安装ServiceStack.Razor包:
PM> Install-Package ServiceStack.Razor
这将配置项目,使ServiceStack's Razor support 。从那里,你可以通过你的请求或响应DTO,e.g后命名其添加为您服务的看法:
/Views
RequestDto.cshtml
/Shared
_Layout.cshtml
至于这对现有的服务视图模式,@model
将是您的服务响应DTO。
如果一切正确配置,从浏览器调用您的现有服务(或任何HTTP请求与Accept: text/html
)将返回您的视图的输出,而不是ServiceStack的built-in auto HTML output。