I'm trying to get self-hosted Nancy to return a razor view and I can't get it to work. The sample in the Nancy source code uses a web project, but the page they have doesn't say this is required. I've tried specifying the config sections but again they say "This step is totally optional" (italics are theirs). Tracing through the source it doesn't look like razor is a valid view engine, but I don't see where I can add it either in the config or in my own NancyModule... Any help would be appreciated.
When I finally figured out they were looking in the views folder, it seems that the cshtml is a supported extension, but the DefaultViewFactory doesn't have it associated with a view engine so I get null:
My code:
public Module1()
{
Get["/me"] = parms =>
{
return View["Static.html"]; // WORKS!
};
Get["/you"] = parms =>
{
dynamic model = new ExpandoObject();
//return View["~/Static.cshtml", model];
//return View["/Static.cshtml", model];
return View["Static.cshtml", model]; // blank page, no error or anything
};
}
Static.cshtml is just an html page that says "Hello, world!"
console,form and wpf projects locate view files at same location as executable file. it means you must copy your view.cshtml files to your projects bin\debug folder to work on debug mode.
So: mark your .cshtml files as copy to output
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