I was hoping someone can catch something that I missed. I am bundling my javascript files in BundleConfig.cs, which is in the folder App_Data
like this
我希望有人能抓到我错过的东西。我将我的javascript文件捆绑在BundleConfig.cs中,就像这样在App_Data文件夹中
bundles.Add(new ScriptBundle("~/bundles/customScript").Include(
"~/Views/Summary/storedata.js",
"~/Views/Summary/UploadData.js",
"~/Views/Summary/manipulateData.js"));
When I load the page it says that the resource can not be found. I double check and the path is correct. It seems that the resources in View can not be loaded. I have some scripts from a library in the Scripts folder that is able to load
当我加载页面时,它表示无法找到资源。我仔细检查,路径是正确的。似乎无法加载View中的资源。我有一些脚本来自Scripts文件夹中的库,可以加载
bundles.Add(new ScriptBundle("~/bundles/frameworkScripts").Include(
...
"~/Scripts/jquery.browser.min.js",
"~/Scripts/jquery.inputmask.bundle.js",
....
Is there something I am forgetting to check? Maybe help point me in the right direction?
有什么我忘了检查?也许帮助我指出正确的方向?
Update
As requested I am loading the bundle here in my _Layout.cshtml which is in the shared folder and that folder is in the Views folder
根据要求,我在我的_Layout.cshtml中加载了这个包,它位于共享文件夹中,该文件夹位于Views文件夹中
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<!-- Meta tag used for the finger gesture needed for swiping -->
<meta name="viewport" content="minimum-scale=1.0, maximum-scale=1.0, width=device-width, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
@Styles.Render("~/Content/css")
@Styles.Render("~/Content/themes/base/css")
....
@Scripts.Render("~/bundles/frameworkScripts")
....
@Scripts.Render("~/bundles/customScript")
The error that I am getting is in the web console, this is just one of the error the other is the same error diff. resource
我得到的错误是在Web控制台中,这只是错误之一,另一个是相同的错误差异。资源
Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:53228/Views/Summary/manipulateData.js
2 个解决方案
#1
0
This has to do with the fact that in ASP.NET MVC you cannot access a Views
directory via a URL. So that you'd have to go through a controller to get to a view. That's how routing works.
这与ASP.NET MVC中无法通过URL访问Views目录这一事实有关。因此,您必须通过控制器才能进入视图。这就是路由的工作原理。
For this reason there is a Scripts
directory (and Content
directory for css, images, etc.). If there are many scripts per view, create a directory for each view under Scripts
.
因此,有一个Scripts目录(以及css,images等的Content目录)。如果每个视图有许多脚本,请在“脚本”下为每个视图创建一个目录。
#2
0
In a standard ASP.Net MVC project, there are 2 Web.config files (one in the root, one in the Views Diectory). In the second Web.config, you will find the following:
在标准的ASP.Net MVC项目中,有2个Web.config文件(一个在根目录中,一个在Views Diectory中)。在第二个Web.config中,您将找到以下内容:
<httpHandlers>
<add path="*" verb="*"
type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
this stops the server from serving any files directly from the Views folder or subfolders. You can replace it with the following code and still be safe:
这会阻止服务器直接从Views文件夹或子文件夹中提供任何文件。您可以使用以下代码替换它并仍然是安全的:
<httpHandlers>
<add path="*.aspx" verb="*"
type="System.Web.HttpNotFoundHandler"/>
<add path="*.master" verb="*"
type="System.Web.HttpNotFoundHandler"/>
<add path="*.ascx" verb="*"
type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
#1
0
This has to do with the fact that in ASP.NET MVC you cannot access a Views
directory via a URL. So that you'd have to go through a controller to get to a view. That's how routing works.
这与ASP.NET MVC中无法通过URL访问Views目录这一事实有关。因此,您必须通过控制器才能进入视图。这就是路由的工作原理。
For this reason there is a Scripts
directory (and Content
directory for css, images, etc.). If there are many scripts per view, create a directory for each view under Scripts
.
因此,有一个Scripts目录(以及css,images等的Content目录)。如果每个视图有许多脚本,请在“脚本”下为每个视图创建一个目录。
#2
0
In a standard ASP.Net MVC project, there are 2 Web.config files (one in the root, one in the Views Diectory). In the second Web.config, you will find the following:
在标准的ASP.Net MVC项目中,有2个Web.config文件(一个在根目录中,一个在Views Diectory中)。在第二个Web.config中,您将找到以下内容:
<httpHandlers>
<add path="*" verb="*"
type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
this stops the server from serving any files directly from the Views folder or subfolders. You can replace it with the following code and still be safe:
这会阻止服务器直接从Views文件夹或子文件夹中提供任何文件。您可以使用以下代码替换它并仍然是安全的:
<httpHandlers>
<add path="*.aspx" verb="*"
type="System.Web.HttpNotFoundHandler"/>
<add path="*.master" verb="*"
type="System.Web.HttpNotFoundHandler"/>
<add path="*.ascx" verb="*"
type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>