【问题标题】:How to display pages from a nested folder in asp.net core 3.1如何在 asp.net core 3.1 中显示嵌套文件夹中的页面
【发布时间】:2020-05-30 00:19:01
【问题描述】:

当我尝试运行应用程序时出现以下异常,我知道原因是它找不到文件。但是提供此文件的任何替代方法?

文件夹结构:

我尝试使用“UseContentRoot”,但无法解决问题

   CreateHostBuilder(args).UseContentRoot(Directory.GetCurrentDirectory() + "\\PersonalTab").Build().Run();

例外: InvalidOperationException:未找到视图“索引”。搜索了以下位置: /Views/Home/Index.cshtml /Views/Shared/Index.cshtml

当我尝试从“PersonalTab”文件夹外部查看视图时,它工作正常,但根据我的要求,它需要位于“PersonalTab”文件夹内?

注意:我使用的是 asp.net core 3.1

【问题讨论】:

    标签: asp.net-mvc razor asp.net-core-3.1


    【解决方案1】:

    您可以将 RazorViewEngineOptions 配置为也在 PersonalTab 文件夹下查看。我尝试重新创建一个项目并将其添加到 Startup 类 ConfigureServices 方法中,它对我有用:

    services.Configure<RazorViewEngineOptions>(o =>
            {
                o.ViewLocationFormats.Add("/PersonalTab/Views/{1}/{0}" + RazorViewEngine.ViewExtension);
                o.ViewLocationFormats.Add("/PersonalTab/Views/Shared/{0}" + RazorViewEngine.ViewExtension);
            });
    

    参考:Change Default Location of Views and Razor Pages in ASP.NET Core

    【讨论】:

      猜你喜欢
      • 2021-11-06
      • 2023-04-03
      • 2020-01-16
      • 2021-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多