Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nancy Self Host blank response with Razor view [closed]

Tags:

c#

razor

nancy

Resolved in Nancy 0.6


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.

View Engines

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:

enter image description here

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

like image 881
Jason Goemaat Avatar asked Jul 14 '11 23:07

Jason Goemaat


1 Answers

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

like image 67
SalmanAA Avatar answered Sep 18 '22 12:09

SalmanAA