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.
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.
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?
Should we create seperate .js
files for each individual view or combine all the .js
files for different views into a large file?
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.