【问题标题】:Adding sub-directory to “View/Shared” folder in ASP MVC core and calling the view在 ASP MVC 核心的“View/Shared”文件夹中添加子目录并调用视图
【发布时间】:2020-02-14 09:38:31
【问题描述】:

我在将子文件夹添加到项目中的 /Views/Shared 时遇到了一些问题。 这是我目前的结构:

/Views/Shared/AreasNavs/{0}.cshtml

我从网上找到了一些解决方案:

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

...这个解决方案来自Adding sub-directory to “View/Shared” folder in ASP.Net MVC and calling the view

services.AddMvc()
    .AddRazorOptions(opt => {
        opt.ViewLocationFormats.Add("/Views/{1}/Partials/{0}.cshtml");
        opt.ViewLocationFormats.Add("/Views/Shared/Partials/{0}.cshtml");
    });

但没有什么是工作。

更新。此问题与区域申诉有关

你有什么想法吗?

谢谢!

【问题讨论】:

    标签: c# asp.net-core


    【解决方案1】:

    我刚刚遇到了同样的问题。该问题与区域注册有关。而不是

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

    使用区域的视图位置

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

    【讨论】:

      猜你喜欢
      • 2011-06-25
      • 2021-08-14
      • 1970-01-01
      • 2014-07-29
      • 1970-01-01
      • 2020-01-12
      • 1970-01-01
      • 1970-01-01
      • 2010-11-18
      相关资源
      最近更新 更多