正确的外部JavaScript即看在ASP .NET MVC应用程序文件放置 [英] Correct external javascript-per-view file placement in an ASP .NET MVC Application

查看:120
本文介绍了正确的外部JavaScript即看在ASP .NET MVC应用程序文件放置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个ASP .NET MVC应用程序,什么是正确的文件夹放置外部JavaScript文件特别是每个视图?大多数观点都需要Javascript code,我正打算在外部文件中写的,但我不知道我是否应该在下一个下拉他们的意见或脚本文件夹的子文件夹。

In an ASP .NET MVC application, what's the correct folder to place external javascript files particular to each view? Most views require javascript code that I'm planning to write in external files, but I'm not sure if I should drop them next to the views or in subfolders of the Scripts folder.

推荐答案

脚本文件夹是最好的。 %= Url.Content(〜/脚本/ DIR /的script.js)%>

The Scripts folder is best. You can reference them with <%= Url.Content("~/Scripts/dir/script.js") %>

基本MVC文件夹结构是由组类型的东西 - 控制器都在一起,意见都在一起,脚本都在一起,等使用一致的命名约定,因此您可以轻松地找到正确的脚本

The basic MVC folder structure is to group things by type - Controllers all together, Views all together, Scripts all together, etc. Use a consistent naming convention so you can easily locate the correct script.

这种方法的好处是,你可以轻松地将您的脚本到一个单独的静态文件服务器上,如果有需要,因为它们都是在相同的根。如果你写你自己替换 Url.Content ,你甚至可以做到这一点,只有一个code更改为一种功能。

A benefit of this approach is that you can easily move your scripts to a separate static-file server, if the need arises, because they are all under the same root. If you write your own replacement for Url.Content, you can even do this with only a code change to one function.

这篇关于正确的外部JavaScript即看在ASP .NET MVC应用程序文件放置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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