ASP.NET核心1.1 - 在视图文件夹下放置js文件404

时间:2017-02-24 10:49:29

标签: asp.net asp.net-core

我非常喜欢ASP.NET Core 1.1的文件夹结构“Features folder”(此处为https://scottsauber.com/2016/04/25/feature-folder-structure-in-asp-net-core/)。

所以这是我的结构......

- Features
  - Home
    - index.cshtml
    - index.js
    - homeController.cs

在我的index.cshtml中,我有这个js链接:

<script src="/home/index.js"></script>

但是当我运行应用程序时,我可以看到index.cshtml没问题,但我在index.js文件中遇到404错误。

我尝试更改"Build action" to "Content" ...但没有帮助。

在创业时,我有...... app.UseStaticFiles();

知道如何让ASP.Net核心1.1接受放置在视图文件夹中的文件吗?

1 个答案:

答案 0 :(得分:4)

静态内容在wwwroot文件夹中提供,或者在wwwroot / home / index.js中移动你的index.js(推荐的解决方案)或者将你的wwwroot配置更改为你的功能文件夹上的指针(不推荐)