【问题标题】:CSS not rendering View in asp.net core Mvc applicationCSS未在asp.net核心Mvc应用程序中呈现视图
【发布时间】:2020-07-20 16:11:30
【问题描述】:

我有一个使用布局的简单视图。当页面运行时,布局文本和视图中的文本加载得很好。但是,我附加的css文件不起作用

【问题讨论】:

  • 请提供有关问题的详细信息。在浏览器的调试工具中,在网络选项卡上,是否加载了 CSS 文件?哪些特定的样式规则和目标 HTML 未能应用该样式?

标签: asp.net-core model-view-controller


【解决方案1】:

您可以在Shared/_layout.cshtml的<head></head>中添加@RenderSection("heads", required: false)。并在您的视图中使用@section heads{},将您想要的css添加到您的视图中。

这是一个演示:

布局:

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - case1_5_26_</title>
    @RenderSection("heads", required: false)
</head>

查看:

@section heads{
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="~/css/site.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" />
}

结果:

【讨论】:

    猜你喜欢
    • 2016-07-11
    • 1970-01-01
    • 1970-01-01
    • 2017-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2017-01-22
    相关资源
    最近更新 更多