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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With