带有Razor的ServiceStack-模型为空(部署到Azure)

带有Razor的ServiceStack-模型为空(部署到Azure),azure,servicestack-razor,Azure,Servicestack Razor,使用ServiceStack/Razor时,我仅在Azure中呈现视图时遇到问题 以下是本地页面的屏幕截图: ! 以下是我的服务回应: return new HttpResult(new IndexResponse("Home | Northeast Healthcare Recruitment") { TotalJobs = metadata.TotalJobs, GroupedJobTypeCounts = groupedJobTypeCounts, MostRec

使用ServiceStack/Razor时,我仅在Azure中呈现视图时遇到问题

以下是本地页面的屏幕截图:

!

以下是我的服务回应:

return new HttpResult(new IndexResponse("Home | Northeast Healthcare Recruitment")
{
    TotalJobs = metadata.TotalJobs,
    GroupedJobTypeCounts = groupedJobTypeCounts,
    MostRecentJobs = new List<JobListingSummary>()
})
{
    View = "Index"
};
我的观点的开头如下所示:

@inherits ViewPage<NEHCR.ServiceModel.IndexResponse>

@section head{

}

<section id="content" class="nehcr-content">
    <!-- JOB SEARCH START -->
    <section class="nehcr-search-hero">
        <div class="container">
            <div>
                <div class="nehcr-search-text">
                    <h1 class="nehcr-search-text-header">Search from @Model.TotalJobs job offers</h1>
                    <p class="nehcr-search-text-p">Your career starts here.</p>
                </div>
                <form method="GET" action="/jobs" class="nehcr-search-wrap nehcr-row">
@继承ViewPage
@科长{
}
从@Model.TotalJobs职位提供中搜索

你的职业生涯从这里开始

我的web.config是:

<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" />
  <add key="ConnectionString" value="" />
</appSettings>
<connectionStrings>
  <add name="ConnectionString" connectionString="" providerName="System.Data.SqlClient" />
</connectionStrings>
<!--
  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.6.2" />
    </system.Web>
-->
<system.web>
  <compilation debug="true" targetFramework="4.6.2">
    <buildProviders>
      <add extension=".cshtml" type="ServiceStack.Razor.CSharpRazorBuildProvider, ServiceStack.Razor"/>
    </buildProviders>
  </compilation>
  <httpRuntime targetFramework="4.5"/>
  <httpHandlers>
    <add path="*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*"/>
  </httpHandlers>
  <customErrors mode="Off">
  </customErrors>
</system.web>
<system.webServer>
  <validation validateIntegratedModeConfiguration="false"/>
  <urlCompression doStaticCompression="true" doDynamicCompression="false"/>
  <handlers>
    <add path="*" name="ServiceStack.Factory" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true"/>
  </handlers>
</system.webServer>
<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="NEHCR"/>
      <add namespace="NEHCR.ServiceModel"/>
    </namespaces>
  </pages>
</system.web.webPages.razor>


感谢您的帮助。

我不明白您为什么要在
IndexResponse
的参数中添加
new
,这对方法毫无意义HttpResult将对象作为参数?你的意思是不是要在手前重新整理?或者只是说returnnewindexresponse?当你说它工作正常时,你是说
Index.cshtml
页面被渲染了吗?因为从你的网站上我刚刚看到了,这表明响应DTO与任何页面都不匹配。此外,您还需要确保每个页面在整个
/Views/
文件夹中都具有唯一的名称,例如,只有1个
Index.cshtml
页面可以通过
Index
Request DTO或
View=“Index”
@mythz解决。是的,页面在本地呈现。我只有一个索引页。将用截图编辑帖子。好吧,看起来它可以找到正确的页面,糟透了,它只发生在远程。您是否可以尝试在方法中添加
[DefaultView(“Index”)]
,而不是在
HttpResult
中返回
IndexResponse
,以查看这是否有帮助?否则,您的页面中可能会出现
NullReferenceException
,从这里无法确定,因此我建议您删除页面的部分内容,直到NRE消失。还要注意的是,所有DTO都应该有一个无参数构造函数,这样它们就可以反序列化。我不明白为什么要在
IndexResponse
的参数中添加
new
,这对方法来说毫无意义HttpResult将对象作为参数?你的意思是不是要在手前重新整理?或者只是说returnnewindexresponse?当你说它工作正常时,你是说
Index.cshtml
页面被渲染了吗?因为从你的网站上我刚刚看到了,这表明响应DTO与任何页面都不匹配。此外,您还需要确保每个页面在整个
/Views/
文件夹中都具有唯一的名称,例如,只有1个
Index.cshtml
页面可以通过
Index
Request DTO或
View=“Index”
@mythz解决。是的,页面在本地呈现。我只有一个索引页。将用截图编辑帖子。好吧,看起来它可以找到正确的页面,糟透了,它只发生在远程。您是否可以尝试在方法中添加
[DefaultView(“Index”)]
,而不是在
HttpResult
中返回
IndexResponse
,以查看这是否有帮助?否则,您的页面中可能会出现
NullReferenceException
,从这里无法确定,因此我建议您删除页面的部分内容,直到NRE消失。还要注意的是,所有DTO都应该有一个无参数构造函数,以便可以反序列化它们。
@inherits ViewPage<NEHCR.ServiceModel.IndexResponse>

@section head{

}

<section id="content" class="nehcr-content">
    <!-- JOB SEARCH START -->
    <section class="nehcr-search-hero">
        <div class="container">
            <div>
                <div class="nehcr-search-text">
                    <h1 class="nehcr-search-text-header">Search from @Model.TotalJobs job offers</h1>
                    <p class="nehcr-search-text-p">Your career starts here.</p>
                </div>
                <form method="GET" action="/jobs" class="nehcr-search-wrap nehcr-row">
<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" />
  <add key="ConnectionString" value="" />
</appSettings>
<connectionStrings>
  <add name="ConnectionString" connectionString="" providerName="System.Data.SqlClient" />
</connectionStrings>
<!--
  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.6.2" />
    </system.Web>
-->
<system.web>
  <compilation debug="true" targetFramework="4.6.2">
    <buildProviders>
      <add extension=".cshtml" type="ServiceStack.Razor.CSharpRazorBuildProvider, ServiceStack.Razor"/>
    </buildProviders>
  </compilation>
  <httpRuntime targetFramework="4.5"/>
  <httpHandlers>
    <add path="*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*"/>
  </httpHandlers>
  <customErrors mode="Off">
  </customErrors>
</system.web>
<system.webServer>
  <validation validateIntegratedModeConfiguration="false"/>
  <urlCompression doStaticCompression="true" doDynamicCompression="false"/>
  <handlers>
    <add path="*" name="ServiceStack.Factory" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true"/>
  </handlers>
</system.webServer>
<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="NEHCR"/>
      <add namespace="NEHCR.ServiceModel"/>
    </namespaces>
  </pages>
</system.web.webPages.razor>
System.NullReferenceException occurred
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=nmhpfpfd
StackTrace:
 at ASP.Views.Home.__Index.Execute() in d:\home\site\wwwroot\Views\Home\Index.cshtml:line 15
 at ServiceStack.Razor.ViewPage`1.WriteTo(StreamWriter writer)
 at ServiceStack.Razor.Managers.RazorPageResolver.ExecuteRazorPageWithLayout(RazorPage razorPage, IRequest httpReq, IResponse httpRes, Object model, IRazorView pageInstance, Func`1 layout)
 at ServiceStack.Razor.Managers.RazorPageResolver.ExecuteRazorPage(IRequest httpReq, IResponse httpRes, Object model, RazorPage razorPage)
 at ServiceStack.Razor.Managers.RazorPageResolver.ProcessRequest(IRequest httpReq, IResponse httpRes, Object dto)
 at ServiceStack.Formats.HtmlFormat.<>c__DisplayClass10_0.<SerializeToStream>b__0(IViewEngine x)
 at ServiceStack.Formats.HtmlFormat.SerializeToStream(IRequest req, Object response, IResponse res)


ServiceStack.Razor.ViewPageBase<TModel>.Model.get returned null.
return new IndexResponse("Home | Northeast Healthcare Recruitment")
{
    TotalJobs = metadata.TotalJobs,
    GroupedJobTypeCounts = groupedJobTypeCounts,
    MostRecentJobs = new List<JobListingSummary>()
};