有些我正在运行一个稍微修改过的Nancy Web Framework自托管演示版本,Nancy.Demo.Hosting.Self。我已将其修改为包括Nancy的Razor视图引擎Nancy.ViewEngines.Razor。当我使用基本的Razor功能时它工作正常,但我遇到了@Render部分视图和布局的麻烦。
ASP.NET之外是否支持这些高级功能?
我从Nancy.Demo.Hosting.Aspnet复制的相同视图似乎在那里工作正常。
我因为没找到'Header'而崩溃了。
以下是观点:
@{ 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>
答案 0 :(得分:4)
您确定您的标头cshtml文件已设置为复制到输出目录吗?
答案 1 :(得分:0)
工作正常,这是我的_Layout.cshtml(注意@RenderBody):
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Test Owin</title>
<link href="/Content/bootstrap/bootstrap.css" rel="stylesheet" />
</head>
<body>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© 2016 - My Test Owin Application</p>
</footer>
</div>
<script src="/Scripts/jquery-3.1.1.js"></script>
<script src="/Scripts/bootstrap.js"></script>
</body>
</html>
这是我的内容,Index.cshtml:
@{ Layout = "_Layout.cshtml"; }
<div class="jumbotron">
<h1>Test Owin</h1>
<p class="lead">Test</p>
<p>
Yesterday, Elon Musk got on stage at the 2016 International Astronautical Congress and unveiled the first real details about the big fucking rocket they’re making.
</p>
</div>