找不到 Razor 模板

Razor templates not found

我第一次尝试 ASP.NET Core RC2。我设法让路由到我的控制器正常工作——如果控制器 returns Content("hello world"),我看到字符串 "hello world" 返回到我的浏览器。

如果控制器 returns View() 但是,我得到一个错误

The View 'Index' was not found. The following locations were searched: /Views/Controller/Index.cshtml ...

我确认视图位于文件夹结构中的正确位置,遵循典型约定。我知道如何在 ASP.NET.

的其他版本中进行这项工作

不过,这是我第一次使用 ASP.NET 核心,我正在尝试手动配置它,所以我想知道我缺少什么 - 也许我需要一些东西来在管道中注册 Razor ,或注册模板的搜索路径?

在我的 project.json 中,我对 Microsoft.AspNetCore.MvcMicrosoft.AspNetCore.Razor 都有依赖关系。

ASP.NET Core RC2 的工作 Program.cs 文件如下所示:

public class Program
{
    public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseStartup<Startup>()
            .Build();

        host.Run();
    }
}

如果 ASP.NET Core 抱怨找不到文件,请确保存在 UseContentRoot(Directory.GetCurrentDirectory())。这将设置 Razor 用于搜索视图的 "base" 路径。