【问题标题】:Environmental variables ignored for Layout in Area区域布局忽略的环境变量
【发布时间】:2016-08-23 19:46:45
【问题描述】:

我的 ASP.NET Core MVC 应用程序有问题。

谁能告诉我为什么环境(名称)的标签助手在位于区域内时不适用于我的(管理)布局页面?

当使用以下代码引用我的脚本时,它在放置到标准 _Layout.cshtml 页面而不是包含在区域(用于管理区域)中的 _Layout.cshtml 时有效。 理想情况下,我试图将我的代码模块化为区域 - 仪表板包含管理区域的这个 _Layout.cshtml 页面。

我发现我所有的 css/js 引用都被包括在内(未缩小和缩小以及 CDN)。所以我把下面的代码放到公共布局和管理布局中。

<environment names="Development">
  Development
</environment>
<environment names="Staging,Production">
  Staging production
</environment>

~/Views/Shared/_Layout.cshtml(公开)

“发展”显示(好)

~/Areas/Dashboard/Views/Shared/_Layout.cshtml(管理)

“Development staging Production”显示(坏)

我的环境变量是 ASPNETCORE_ENVIRONMENT(值为 Development)

我的创业

public Startup(IHostingEnvironment env)
{
    var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
        .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
        .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
        .AddEnvironmentVariables();

    if (env.IsDevelopment())
    {
        // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
        builder.AddUserSecrets();
    }

    Configuration = builder.Build();
}

配置方法 ...

app.UseMvc(routes =>
{
    routes.MapRoute(name: "areaRoute",
                    template: "{area:exists}/{controller=Home}/{action=Index}");

    routes.MapRoute(name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
});

任何帮助都会很棒 - 谢谢。 丹。

【问题讨论】:

  • 引用标签助手的_ViewImports.cshtml是否在该区域的文件夹中?可能需要。
  • 我爱你!添加了 _ViewImports.cshtml 和导入的 taghelpers 参考。添加为答案,我给大快乐的绿色勾号!

标签: c# asp.net-core asp.net-core-mvc


【解决方案1】:

听起来 tagHelper 没有在 Area 中注册,正在被浏览器处理。

environment 之类的 TagHelper 必须在您的 _ViewImports.cshtml 文件中引用,默认情况下该文件仅在 /Views 中,但也应该存在于您的每个区域中。

【讨论】:

    猜你喜欢
    • 2012-09-05
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    • 2020-02-03
    • 2021-10-15
    • 2017-12-14
    • 2012-12-03
    相关资源
    最近更新 更多