Reputation: 18770
I am trying out ASP.NET Core RC2 for the first time. I managed to get routing to my controller working -- if the controller returns Content("hello world")
, I see the string "hello world" returned to my browser.
If the controller returns View()
though, I get an error that
The View 'Index' was not found. The following locations were searched: /Views/Controller/Index.cshtml ...
I confirmed the view is in the right place in the folder structure, following the typical convention. I know how to make this work in other versions of ASP.NET.
It's my first time using ASP.NET Core, though, and I'm trying to configure it all by hand, so I wonder what I'm missing - maybe I need something to register Razor in the pipeline, or to register the search path for the templates?
In my project.json
I have dependencies for both Microsoft.AspNetCore.Mvc
and Microsoft.AspNetCore.Razor
.
Upvotes: 3
Views: 1007
Reputation: 53600
A working Program.cs
file for ASP.NET Core RC2 looks like this:
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.Build();
host.Run();
}
}
If ASP.NET Core is complaining about not being able to find files, make sure that UseContentRoot(Directory.GetCurrentDirectory())
is present. This will set the "base" path that Razor uses to search for views.
Upvotes: 2