Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nancy does not render the view nor extending the layout view

Tags:

c#

mono

nancy

I started learning about C# in Mono (Ubuntu) and Nancy which is a web framework for C#. I am using their "super simple view engine" rendering and I cannot make the code to render the .sshtml file, it just shows as plan text file. Ultimately, I want to use a layout file (layout.sshtml) and each view would replace part of layout file.

I have a hunch that maybe folder structure is not valid and for example login.sshtml does not find the layout.sshtml. But I modified the .csproj file to copy Views folders:

  <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>

I am just confused on why it does not render the view. Any help would be appreciated.

This is the link to my repository

This is folder structure of my project:

├── 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

Screenshot:

enter image description here

like image 881
Node.JS Avatar asked Jun 09 '17 04:06

Node.JS


1 Answers

Found the solution, the issue was using double quotes instead of single quotes in Views folder

For example, change this:

@Master["layout"]


@Section["content"]
   This is content on the register page
@EndSection

to this:

@Master['layout']


@Section['content']
   This is content on the register page
@EndSection

I don't know why, but it solved the layout issue.

By the day, this is the link to working website, it just a simple login, logout, register website.

like image 60
Node.JS Avatar answered Sep 17 '22 18:09

Node.JS