如何组织JavaScript的code在ASP.NET MVC应用程序应用程序、组织、JavaScript、ASP

2023-09-10 16:41:17 作者:你是照亮我的太阳

我们要增加一些Ajax功能的视图页面上。再说了,点击删除或插入按钮和动作将被调用执行CRUD工作在幕后,然后在手术后刷新项目列表。

We are to add some Ajax functions on a view page. Say, click a delete or insert button and an Action will be called to perform a CRUD job behind the scene and then refresh the items list after that operation.

在许多现有的例子中,JavaScript code为内内嵌在浏览页<脚本> 标记。由于有一个观点可能需要平时的许多功能。就是说,当插入一条记录,就会有功能来收集表单数据,验证数据(这部分可以很长),并调用由 $的动作。阿贾克斯()。出于这个原因,我们正在考虑将所有这些的JavaScript到一个单独的的.js 文件。

In many existing examples, the javascript code is embeded in the view page within the <script> tag. Since there are usually many functions that one view may need. Say, when insert a record, there will be function to collect the form data, validate the data (this part can be very long), and call the action by $.ajax(). For this reason, we are thinking about place all those javascript into a separate .js file.

那么,什么是这个专业的做法呢?如果我们把同一文件夹下的的.js 文件的浏览?或者应该是地方所有的人都到剧本文件夹和借鉴呢?

So, what is the professional practice in this? Should we place the .js files under the same folder with its Views? Or should be place all of them into the Script folder and reference from there?

如果我们创建单独的的.js 文件为每个单独的视图或将所有的的.js 文件不同的看法成一个大文件?

Should we create seperate .js files for each individual view or combine all the .js files for different views into a large file?

此外,我们爱我们​​如何能够C组#code。使用#地区,以便崩溃。有没有什么类似的JavaScript?它只是成长长的太容易了。

Also, we love how we can group C# code using #region so as to collapse. Is there anything similar in JavaScript? It just grows lengthy too easily.

感谢您的任何有益的建议。

Thank you for any helpful advice.

推荐答案

可能你会发现这个有用