如何在ASP.net Core中添加js和CSS文件? [英] How to add js and css files in ASP.net Core?

查看:1157
本文介绍了如何在ASP.net Core中添加js和CSS文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已被分配将应用程序从MVC迁移到ASP.net Core,我是ASP.net Core的新手.在MVC中,我们有BundleConfig.cs,并且在其中添加了对css和js文件的引用,它如何在ASP.net Core中工作?假设我创建了一个test.jsMyStyle.css类,这是在每个视图中添加对它的引用的最佳方法吗?我应该将.js.css文件放置在wwwroot/jswwwroot/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>标记内添加了引用:

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文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆