ASP.Net MVC3:将.js文件视图,而不是脚本文件夹中的文件附近 [英] ASP.Net MVC3: Place .js files near View instead of Scripts folder

查看:95
本文介绍了ASP.Net MVC3:将.js文件视图,而不是脚本文件夹中的文件附近的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们想从我们的观点剃刀(这样我们可以测试)分裂出来的JavaScript。我们能否找到他们附近有甚则对应在脚本文件夹视图的.js文件?例如,我们希望看到这个解决方案资源管理:

We'd like to split out the javascript from our Razor views (so we can test). Can we locate the .js files near the views they correspond with rather then in the Scripts folder? For example, we'd like to see this in solution explorer:

MyMvcProject
    - Views
      - Home
        - About.cshtml
        - About.js

不过,我不知道要引用来自.cshtml视图中的.js文件。

However, I don't know to references the .js file from the .cshtml view.

推荐答案

有关安全方面的原因,asp.net,MVC块从URL年代/浏览次数夹中的所有文件访问。这可以到处工作,但我建议这样做并不是出于安全原因。

For security reasons, asp.net-mvc blocks all file access to the /Views folder from URL's. This can be worked around, but I would suggest NOT doing this for security reasons.

您通常应该留在Scripts文件夹脚本,特别是全系统的,如jQuery和不显眼的东西。这是使他们能够通过的NuGet更容易更新的新版本或错误修正被释放。

You should generally leave your scripts in Scripts folder, particularly the system-wide ones such as jquery and the unobtrusive stuff. This is so they can be more easily updated through NuGet as new versions or bugfixes are released.

我不知道为什么你有测试问题,让他们在默认位置。

I'm not sure why you have a problem with testing and leaving them in the default location.

这篇关于ASP.Net MVC3:将.js文件视图,而不是脚本文件夹中的文件附近的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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