ASP.NET MVC - 你在哪里把你的.js文件,如果你不想将它们存储在/脚本? [英] ASP.NET MVC - Where do you put your .js files if you dont want to store them in /Scripts?
问题描述
我有一些,我想存储在同一目录作为自己的看法.js文件(它们是具体到一个视图 - 它不仅仅是保持独立的JavaScript从视图的HTML)
I have a number of .js files that I would like to be stored in the same directories as their views (they're specific to a view - its simply to keep the javascript separate from the view's HTML)
然而,将它们添加到 /查看/ ControllerName /
目录不会工作,因为当一个请求到Web服务器取得的.js文件:
However, adding them to the /Views/ControllerName/
directory wont work because when a request is made to the webserver for the .js file:
<script type="text/javascript" src="/Views/ControllerName/myscript.js"></script>
这将基本上在若干意见控制器,这显然存在犯规被引导。
It would essentially be directed at the 'Views' controller which obviously doesnt exist.
更新
从我已阅读,在Global.asax.cs中的RegisterRoutes方法添加以下IgnoreRoute应该允许访问任何请求的.js文件:
From what I have read, adding the following IgnoreRoute in the global.asax.cs RegisterRoutes method should permit access to any requested .js file:
routes.IgnoreRoute("{resource}.js/{*pathInfo}");
不过,我似乎无法得到它的工作?
However, I cant seem to get it to work?
推荐答案
解决
在找到并测试了一些职位(最确凿后的这里),我不可能去工作,下面的解决了困扰:
After having found and tested a number of posts (most conclusive post here) that I couldnt get to work, the following solves the puzzle:
在的Global.asax
,添加以下code到的RegisterRoutes
方法:
In the Global.asax
, add the following code to the RegisterRoutes
method:
routes.IgnoreRoute("{file}.js");
这里有一个伟大的职位描述这个和附加活动的这里
这篇关于ASP.NET MVC - 你在哪里把你的.js文件,如果你不想将它们存储在/脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!