How to add js and css files in ASP.net Core?(如何在 ASP.net Core 中添加 js 和 css 文件?)
问题描述
我被分配将应用程序从 MVC 迁移到 ASP.net Core,我是 ASP.net Core 的新手.在 MVC 中,我们有 BundleConfig.cs 并在其中添加对 css 和 js 文件的引用,它在 ASP.net Core 中是如何工作的?假设我创建了一个 test.js 和一个 MyStyle.css 类,这是在每个视图中添加对它的引用的最佳方式吗?我应该将 .js 和 .css 文件放在 wwwroot/js 和 wwwroot/css 中吗?
I've been assigned to migrate an application from MVC into ASP.net Core, I'm new to ASP.net Core. In MVC we have BundleConfig.cs and in there we add references to our css and js files, how does it work in ASP.net Core? Let's say that I created a test.js and a MyStyle.css class, which is the best way to add references to it in every view? Should I place the .js and .css files inside wwwroot/js and wwwroot/css?
推荐答案
我在 _Layout 视图中添加了引用,在 <environment> 标签内:p>
I added the references inside the _Layout view, inside the <environment> tags:
<environment names="Development">
<link rel="stylesheet" href="~/css/MyCss.css" />
</environment>
如果有人知道更好的方法,我会欢迎它
If anyone knows a better way I would welcome it
这篇关于如何在 ASP.net Core 中添加 js 和 css 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 ASP.net Core 中添加 js 和 css 文件?
基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
