I am successfully using the Nancy Razor engine. I have a _Master.cshtml
Layout which defines a razor @section
for my javascript and others for my @Html.Partial()
and CSS files.
This all works fine.
Edit 1 See here for more useful info including a neat extension method that fixes the problem:
_Master Layout
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>
<!DOCTYPE html>
<html lang="en">
<head>
//Head stuff
@RenderSection("CSS", required: false)
</head>
<body>
//Body Stuff
@RenderBody()
@RenderSection("Partial", required: false)
@RenderSection("JS", required: false)
</body>
</html>
A Example View
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>
@{
Layout = "_Master.cshtml";
}
// View HTML
@section Partial{
@Html.Partial("Modal/FindWizard")
}
@section JS{
<script src="/Scripts/Coffee/example.view.min.js"> </script>
}
You can see from the Example View above that I have included a Partial
called FindWizard. I would like this file to also take advantage of the razor sections defined in the _Master Layout.
Something like this:
FindWizard Partial with @sections
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>
<div>
//.. Wizard HTML
</div>
@section CSS{
<link href="/Content/css/bootstrap-wizard.css" rel="stylesheet" />
}
@section JS{
<script src="/Scripts/min/bootstrap-wizard.min.js"></script>
}
I have tried this but I cannot get the razor @sections from the Partial file to render into the final response.
Is this technique possible? Maybe its a plain bad idea as it may lead to duplicate js files being included if a Partial is re-used in the same view?
Thanks