自托管 Nancy 控制台应用程序中的 Razor 视图引擎问题
有些我正在运行 Nancy Web Framework 自托管演示的稍微修改版本,Nancy.Demo.Hosting.Self。我对其进行了修改,以包含 Nancy 的 Razor 视图引擎 Nancy.ViewEngines.Razor。当我使用基本的 Razor 功能时,它工作得很好,但我在使用 @Render 部分视图和布局时遇到了麻烦。
这些高级功能在 ASP.NET 之外是否受支持?
我从 Nancy.Demo.Hosting.Aspnet 复制的相同视图似乎在那里工作得很好。
我因找不到“标题”而崩溃。
这是视图:
@{ Layout = "razor-layout.cshtml"; }
@section Header {
<!-- This comment should appear in the header -->
}
<h1>Hello @Model.FirstName</h1>
<p>This is a sample Razor view!</p>
@section Footer {
<p>This is footer content!</p>
}
和布局
<html>
<head>
<title>Razor View Engine Demo - @Model.FirstName</title>
@RenderSection("Header")
</head>
<body>
<div id="body">@RenderBody()</div>
<div id="footer">@RenderSection("Footer")</div>
<div id="optional">@RenderSection("Optional", false)</div>
</body>
</html>
Some I'm running a slightly modified version of the Nancy Web Framework self hosting demo, Nancy.Demo.Hosting.Self. I've modified it to include the Nancy's Razor view engine, Nancy.ViewEngines.Razor. It works fine when I use basic Razor features, but I've run into trouble with @Render partial views and layouts.
Are these advanced features supported outside of ASP.NET?
The same views I copied from Nancy.Demo.Hosting.Aspnet, seem to work fine there.
I'm getting a crash about not finding my 'Header'.
Here's the view:
@{ Layout = "razor-layout.cshtml"; }
@section Header {
<!-- This comment should appear in the header -->
}
<h1>Hello @Model.FirstName</h1>
<p>This is a sample Razor view!</p>
@section Footer {
<p>This is footer content!</p>
}
And the Layout
<html>
<head>
<title>Razor View Engine Demo - @Model.FirstName</title>
@RenderSection("Header")
</head>
<body>
<div id="body">@RenderBody()</div>
<div id="footer">@RenderSection("Footer")</div>
<div id="optional">@RenderSection("Optional", false)</div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定您的头 cshtml 文件设置为复制到输出目录吗?
Are you sure your header cshtml file is set to copy to the output directory?
工作正常,这是我的_Layout.cshtml(注意@RenderBody):
这是我的内容,Index.cshtml:
Works fine, here is my _Layout.cshtml (note the @RenderBody):
and here is my content, Index.cshtml: