-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Razor View Engine
Installing Razor
Simply reference Nancy.ViewEngines.Razor.dll
and return views ending in cshtml
it's that simple. Please note that as of yet certain feautures you might be used to from MVC/ASP.NET are unavailable such as strongly typed views. You can sorta mock strongly typing views, for those of us who have complex object graphs, by specifing
@MyType model = (MyType)Model;
at the top of your view.
Configuring Razor.
You can specify assemblies and default namespaces that razor needs to use whilst compiling the views by bootstrapping your own IRazorConfiguration implementation. This step is totally optional if you don't require additional references or namespaces in your view.
The default RazorConfiguration looks in app or web.config in the razor section.
Step 1: Create a custom configSection
<configSections>
<section name="razor" type="Nancy.ViewEngines.Razor.RazorConfigurationSection, Nancy.ViewEngines.Razor" />
</configSections>
Step 2: Configure Razor!
<razor disableAutoIncludeModelNamespace="false">
<assemblies>
<add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add assembly="SolrNet" />
<add assembly="SyslogServerLibrary" />
</assemblies>
<namespaces>
<add namespace="SolrNet" />
<add namespace="SyslogServerLibrary" />
</namespaces>
</razor>
Pretty self explanatory except disableAutoIncludeModelNamespace
which by default auto references the assembly of the model you pass into the view.
Use Razor!
Inside NancyModule Constructor
...
Get["/Home/Index"] = param =>
{
var model = repo.GetSomeModel();
return View["index.cshtml", model]
};
- Introduction
- Exploring the Nancy module
- Routing
- Taking a look at the DynamicDictionary
- Async
- View Engines
- Using Models
- Managing static content
- Authentication
- Lifecycle of a Nancy Application
- Bootstrapper
- Adding a custom FavIcon
- Diagnostics
- Generating a custom error page
- Localization
- SSL Behind Proxy
- Testing your application
- The cryptography helpers
- Validation
- Hosting Nancy with ASP.NET
- Hosting Nancy with WCF
- Hosting Nancy with Azure
- Hosting Nancy with Suave.IO
- Hosting Nancy with OWIN
- Hosting Nancy with Umbraco
- Hosting Nancy with Nginx on Ubuntu
- Hosting Nancy with FastCgi
- Self Hosting Nancy
- Implementing a Host
- Accessing the client certificate when using SSL
- Running Nancy on your Raspberry Pi
- Running Nancy with ASP.NET Core 3.1