html - 以 Controller 名称为前缀的 wwwroot 内容

标签 html css asp.net-core

我有一个根本没有加载任何 CSS 的登录页面。这是因为该页面正在寻找以下内容:

enter image description here

我的 wwwroot 文件夹具有 css/login/login.css 结构,但是该页面试图在其前面加上 Controller 名称 (AuthController)。页面的标题看起来像这样:

<head>
    <meta charset="utf-8">
    <title>My Webpage</title>

    <link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/login/login.css">
</head>

我的 Controller 就在一个名为 Controllers 的文件夹中,我的 View 在这样的结构中:Views/Auth/

到目前为止,我还没有使用 _Layout 页面。

我以前没见过这个,我不知道为什么它在 wwwroot 中的内容前加上 Controller 名称的前缀。

最佳答案

尝试将您的样式设置为

    <link rel="stylesheet" href="~/css/login/login.css">

类似于如何引用相对路径(例如:../css/login/login.css),您可以在 Razor 中使用 引用虚拟根路径~ 运算符。

一般来说,我发现 ~ 更有用,因为您可以更改 View 的位置并仍然引用相同的位置。

关于html - 以 Controller 名称为前缀的 wwwroot 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47796337/

相关文章:

javascript - fullPage.js 滚动到固定标题

css - 所有网站文本在 Mac 上的 safari 上都是粗体

asp.net-core - 将文本放置在 ChartJS 的图表 Canvas 区域中

azure - 如何从 vNext Build 运行 Azure WebJob?

css - div 内的超链接与在 HTML/CSS 中的标签内分配的类

html - 固定列宽,列数/行数取决于屏幕宽度

javascript - 减慢 html anchor 链接

Javascript 'Print' 按钮直接到 'Save as PDF'

css - 错误:C:未初始化的常量 FontAwesome::Sass::VERSION 使用 --trace 运行以查看完整的回溯

c# - 验证 Google Id token