1

我正在使用 Razor 运行 Asp.Net 主机 (ServiceStack.Host.AspNet 4.0.30.0) - ServiceStack 4.0.30.0 项目。

.Net 框架目标:4.5.1

该项目编译得很好,但是我在使用带有 Update 2 的 Visual Studio 2013 的 Razor 视图中没有得到任何智能感知。

关于如何让智能感知在 ServiceStack Razor 视图中工作的任何想法?我的机器也安装了 MVC 4 和 5。

在此处输入图像描述

这也是我的 web.config 的副本...

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <!--
    For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.

    The following attributes can be set on the <httpRuntime> tag.
      <system.Web>
        <httpRuntime targetFramework="4.5.1" />
      </system.Web>
  -->
  <system.web>
    <httpRuntime />
    <compilation targetFramework="4.5.1" debug="true">
    <buildProviders>
        <add extension=".cshtml" type="ServiceStack.Razor.CSharpRazorBuildProvider, ServiceStack.Razor" />
      </buildProviders></compilation>
    <pages controlRenderingCompatibilityVersion="4.0" />
  <httpHandlers>
      <add path="*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" />
    </httpHandlers></system.web>
  <system.web.webPages.razor>
    <pages pageBaseType="ServiceStack.Razor.ViewPage">
      <namespaces>
        <add namespace="windows_consumer81_demo.Models" />
        <add namespace="windows_consumer81_demo.Models.Scenario" />
        <add namespace="windows_consumer81_demo.Localization" />
        <add namespace="System" />
        <add namespace="ServiceStack" />
        <add namespace="ServiceStack.Html" />
        <add namespace="ServiceStack.Razor" />
        <add namespace="ServiceStack.Text" />
        <add namespace="ServiceStack.OrmLite" />
        <add namespace="windows_consumer81_demo" />
      </namespaces>
    </pages>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc" />
  </system.web.webPages.razor>
  <appSettings>
    <add key="DebugMode" value="true" />
    <add key="unsupportedRedirect" value="unsupported.html" />
    <add key="vs:EnableBrowserLink" value="false" />
  <add key="webPages:Enabled" value="false" /></appSettings>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <add path="*" name="ServiceStack.Factory" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
    </handlers>
  </system.webServer>
</configuration>

在此处输入图像描述

4

1 回答 1

2

我想它应该工作的方式是你添加的所有命名空间都web.config应该有 IntelliSense:

<system.web.webPages.razor>
  <pages pageBaseType="ServiceStack.Razor.ViewPage">
    <namespaces>
    <add namespace="YourNameSpaceHere" />
    <add namespace="SomeServiceStackNameSpace" />
    . . .

然后在 .cshtml 文件中添加:

@inherits ViewPage<YourModelClassName>

不幸的是,这并不总是有效。它可以编译,但您没有得到 IntelliSense。

但是有一个修复:

在您的.cshtml文件中只需输入完整的命名空间:

@inherits ServiceStack.Razor.ViewPage<Full.Namespace.Of.Your.Model.Class>

如果您使用其他类,只需添加:

@using MyServer.ServiceInterface;
@using MyServer.ServiceModel;

我推荐的另一个技巧是强烈键入您的@Model对象。就在顶部,在@Inherits ViewPage<...>添加内容之后:

@{
  Your.Class.Name TypedModel = Model; 
}

随意重命名TypedModel为更好的名称。

于 2015-04-14T14:35:21.677 回答