Reputation: 213
I know this question was asked month before but was never answered. My program starts normally but after returning View["Index", blogPost] it could not find the Index.cshtml and raises an exception.
Get["/"] = parameters =>
{
var blogPost = new BlogPost
{
Id = 1,
Title = "Test",
Content = "Lorem ipsum...",
Tags = { "c#", "aspnetmvc", "nancy" }
};
return View["Index", blogPost];
};
Exception:
Nancy.RequestExecutionException: Oh noes! ---> Nancy.ViewEngines.ViewNotFoundException: Unable to locate view 'Index' Currently available view engine extensions: sshtml,html,htm,cshtml,vbhtml Locations inspected: views/Home/Index-de-DE,views/Home/Index,Home/Index-de-DE,Home/Index,views/Index-de-DE,views/Index,Index-de-DE,Index`
Upvotes: 4
Views: 4420
Reputation: 24404
We ran into this error and noticed the .cshtml file it was complaining about was not getting copied to the server. The solution was in Visual Studio, in the file's properties, we changed the Build Action
to Content
. This forces it to get included in the build artifacts that are deployed to the server. Similarly you could change the Copy to Output Directory
to Always
as others have mentioned; either works, but I find setting the file as Content a bit more informative.
In your case, I'm guessing you have an Index.cshtml
file which you need to set this property on.
Upvotes: 0
Reputation: 734
If the answer giving my Christian doesn't help you like it didn't help me there is a alternative issue/solution. The alternative is to make sure that the file you created is being copied to the output directory at compile time. You can check it under the properties tab like shown bellow
Upvotes: 1
Reputation: 4932
The exception message tells you where Nancy tried to look for the view:
Locations inspected: views/Home/Index-de-DE,views/Home/Index,Home/Index-de-DE,Home/Index,views/Index-de-DE,views/Index,Index-de-DE,Index
The exception also tells you which file extensions Nancy tried to look for:
Currently available view engine extensions: sshtml,html,htm,cshtml,vbhtml
That is Nancy looks for a file in one of the listed locations with one of the listed extensions.
So the question is if your index.cshtml
is in one the listed folders. If not you can either move it there or set up a view location convention.
Upvotes: 0