c# - Nancy 既不渲染 View 也不扩展布局 View

标签 c# mono nancy

我开始在 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

截图:

enter image description here

最佳答案

找到解决方案,问题是在 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/

相关文章:

c# - Linux 上的 Unity 给出 CS0518 错误。 System.$Everything 未定义

c# - 如何在 Nancy 中针对 Active Directory 进行身份验证?

c# - 我应该如何组织两个对象以便能够将它们加入一个键?

c# - 在 Entity Framework 6 中保存对数据库的更改

c# - 如果 C# 中没有 ANSI 代码页怎么办?

java - 如何构建避免嵌套 Flux block (Flux<Flux <T>>)的响应式架构?

c# - 无法在自宿主应用程序中配置新程序集

nancy - 如何修复使用 Nancy FX 自托管时出现的 AutomaticUrlReservationCreationFailureException

c# - 为什么我会在 xaml 中收到“BoolToRowHeightConverter 在 Windows Presentation Foundation (WPF) 项目中不受支持的错误?

c# - 带有模型绑定(bind)的 Razor 页面 POST 多个表单