Problems with the Razor view engine in the Nancy Console standalone application

Some. I am launching a slightly modified version of the Nancy Web Framework hosting demo, Nancy.Demo.Hosting.Self. I changed it to include the Nancy Razor view engine, Nancy.ViewEngines.Razor. It works great when I use the basic Razor features, but I am having problems with partial views and @Render layouts.

Are these additional features supported outside of ASP.NET?

The same views I copied from Nancy.Demo.Hosting.Aspnet seem to work well there.

I get a crash about not finding my headline.

Here is 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> 
+4
source share
2 answers

Are you sure your header cshtml file is set to copy to the output directory?

+4
source

Works well, here is my _Layout.cshtml (pay attention to @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>&copy; 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> 

and here is my content, 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> 
0
source

Source: https://habr.com/ru/post/1379123/


All Articles