我开始在 Mono (Ubuntu) 和 Nancy 中学习 C#这是 C# 的 Web 框架。我正在使用他们的“ super 简单 View 引擎”渲染,但我无法编写代码来渲染 .sshtml
文件,它只是显示为计划文本文件。最后,我想使用布局文件 (layout.sshtml
),每个 View 都会替换布局文件的一部分。
我有一种预感,文件夹结构可能无效,例如 login.sshtml
找不到 layout.sshtml
。但我修改了 .csproj
文件以复制 Views 文件夹:
<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Debug' ">
<!-- needed to deply views folder -->
<Exec Command="cp -a Views $(OutDir)" />
<!-- needed to deply database if not newer -->
<Exec Command="cp -a -u Database/db.sqlite $(OutDir)" />
</Target>
我只是对为什么它不呈现 View 感到困惑。任何帮助将不胜感激。
This is the link to my repository
这是我项目的文件夹结构:
├── bin
│ └── Debug
│ ├── csharp-practice.exe
│ ├── csharp-practice.exe.mdb
│ ├── db.sqlite
│ ├── Nancy.dll
│ ├── Nancy.Hosting.Self.dll
│ ├── nancy-simple-app.exe
│ ├── nancy-simple-app.exe.mdb
│ └── Views
│ ├── index.sshtml
│ ├── layout.sshtml
│ ├── login.sshtml
│ └── register.sshtml
├── Database
│ ├── DataBaseManager.cs
│ └── db.sqlite
├── LICENSE
├── nancy-simple-app.csproj
├── nancy-simple-app.sln
├── nancy-simple-app.userprefs
├── obj
│ └── x86
│ └── Debug
│ ├── csharp-practice.csproj.FilesWrittenAbsolute.txt
│ ├── csharp-practice.exe
│ ├── csharp-practice.exe.mdb
│ ├── nancy-simple-app.csproj.FilesWrittenAbsolute.txt
│ ├── nancy-simple-app.exe
│ └── nancy-simple-app.exe.mdb
├── packages
│ ├── Nancy.1.4.3
│ │ ├── lib
│ │ │ └── net40
│ │ │ ├── Nancy.dll
│ │ │ └── Nancy.xml
│ │ └── Nancy.1.4.3.nupkg
│ ├── Nancy.Hosting.Self.1.4.1
│ │ ├── lib
│ │ │ └── net40
│ │ │ ├── Nancy.Hosting.Self.dll
│ │ │ └── Nancy.Hosting.Self.xml
│ │ └── Nancy.Hosting.Self.1.4.1.nupkg
│ └── repositories.config
├── packages.config
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
├── ViewModels
│ └── UserModel.cs
└── Views
├── index.sshtml
├── layout.sshtml
├── login.sshtml
└── register.sshtml
截图:
最佳答案
找到解决方案,问题是在 Views folder 中使用双引号而不是单引号
例如,改变这个:
@Master["layout"]
@Section["content"]
This is content on the register page
@EndSection
为此:
@Master['layout']
@Section['content']
This is content on the register page
@EndSection
我不知道为什么,但它解决了布局问题。
By the day, this is the link to working website, it just a simple login, logout, register website.
关于c# - Nancy 既不渲染 View 也不扩展布局 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44449600/