我开始在Mono(Ubuntu)和Nancy学习C#,它是C#的Web框架.我正在使用他们的"超级简单视图引擎"渲染,我无法使代码呈现.sshtml文件,它只是显示为计划文本文件.最终,我想使用布局文件(layout.sshtml),每个视图将替换部分布局文件.
我有一种预感,也许文件夹结构无效,例如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>
Run Code Online (Sandbox Code Playgroud)
我只是为什么它不呈现视图感到困惑.任何帮助,将不胜感激.
这是我项目的文件夹结构:
??? 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
Run Code Online (Sandbox Code Playgroud)
截图:
找到解决方案,问题是在Views 文件夹中使用双引号而不是单引号
例如,更改此:
@Master["layout"]
@Section["content"]
This is content on the register page
@EndSection
Run Code Online (Sandbox Code Playgroud)
对此:
@Master['layout']
@Section['content']
This is content on the register page
@EndSection
Run Code Online (Sandbox Code Playgroud)
我不知道为什么,但它解决了布局问题。
白天,这是工作网站的链接,它只是一个简单的登录、注销、注册网站。