您可以通過添加所需的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。