在ASP.NET MVC中,如何从我的视图文件夹加载脚本? [英] In ASP.NET MVC, how can I load script from my view folder?
问题描述
我已经重构我的一些观的JavaScript的伸到旁边的意见.js文件(而不是在Scripts文件夹关根)。
I've refactored some of my View's javascript out into .js files alongside the views (not in the Scripts folder off root).
在默认情况下,在web.config中的意见处理程序停止这些加载:
By default, the handler in web.config for the views stops these being loaded:
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
不过,我想重写此,让浏览器从这一位置请求.js文件。
However, I want to override this to allow the browser to request .js files from this location.
有谁知道我能做到这一点?
Does anyone know how I can do this?
谢谢,
马克。
Thanks, Mark.
推荐答案
我想我会离开这个脚本在脚本中的位置,但如果你想移动它们,你可以做到以下几点:
I think I would leave the scripts in the scripts location but if you wanted to move them you could do the following:
在web.config文件的顶部下意见寻找
At the top of the web.config file under views look for
<httpHandlers>
<add path="*" verb="*"
type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
和用下面的替换:
<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>
您将需要添加要保留阻止每个文件类型的扩展名。
You will need to add the extension of each file type you want to keep blocked.
这篇关于在ASP.NET MVC中,如何从我的视图文件夹加载脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!