【问题标题】:ASP.NET Core 2.0 ViewLocation - How to add another location that is in an AreaASP.NET Core 2.0 ViewLocation - 如何在区域中添加另一个位置
【发布时间】:2018-03-12 16:34:49
【问题描述】:

我在我的项目中添加了一个名为 /Areas/Views/Shared 的区域 (仅供参考...这是对 Views/Shared 默认值的补充)

我相信我在 Startup 中将其正确添加到服务中(在 services.AddMvc 之后添加)

Startup.cs
        services.Configure<RazorViewEngineOptions>(options => options.ViewLocationFormats.Add("/Areas/Views/Shared/" + RazorViewEngine.ViewExtension));

我收到以下错误:

InvalidOperationException: The partial view 'Areas/Views/Shared/_foo' was not found. 
The following locations were searched:
/Views/Shared/_foo.cshtml

如果 _foo.cshtml 不存在,那么我希望异常如下所示:

InvalidOperationException: The partial view 'Areas/Views/Shared/_foo' was not found. 
The following locations were searched:
/Views/Shared/_foo.cshtml
/Areas/Views/Shared/_foo.cshtml

我阅读了一些帖子,例如下面的项目......但我暂时被卡住了

How to specify the view location in asp.net core mvc when using custom locations?

【问题讨论】:

    标签: asp.net-core-2.0


    【解决方案1】:

    在玩了一些之后,我找到了解决方案...我错过了{0}

    Startup.cs
         services.Configure<RazorViewEngineOptions>(options => options.ViewLocationFormats.Add("/Areas/Views/Shared/{0}" + RazorViewEngine.ViewExtension));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-01
      • 2020-06-14
      • 1970-01-01
      • 1970-01-01
      • 2016-07-31
      • 2018-11-20
      • 1970-01-01
      相关资源
      最近更新 更多