I am wondering how people use JS application for each view.
For example: there's a AssignTask view under Views/Tasks. It should include
AssignTask.js JavaScript file.
My preference is to have this JS file in the same folder as the view itself. But how then I should reference it from the view without fear of changing default controller paths/routing?
Is there something like: Url.CombineViewPath("AssignTask.js")
Other options is to store all the JS files in static folder which is always known. This is fine for 3rd party libraries (ExtJS, jQuery etc), but I want to have the JS related to view nearby that view.
as view folders are not exposed to http, there is no point in putting them there. you should look at one of the javascript AMD libraries like require.js, and use its structure.
nagir
Member
162 Points
184 Posts
JS application location per view
Jan 15, 2008 05:57 AM|LINK
Hello,
I am wondering how people use JS application for each view.
For example: there's a AssignTask view under Views/Tasks. It should include AssignTask.js JavaScript file.
My preference is to have this JS file in the same folder as the view itself. But how then I should reference it from the view without fear of changing default controller paths/routing?
Is there something like:
Url.CombineViewPath("AssignTask.js")
Other options is to store all the JS files in static folder which is always known. This is fine for 3rd party libraries (ExtJS, jQuery etc), but I want to have the JS related to view nearby that view.
Suggestion?
Thanks,
Dmitriy.
ignatandrei
All-Star
134535 Points
21583 Posts
Moderator
MVP
Re: JS application location per view
Nov 18, 2012 08:40 PM|LINK
My preference is to put on Scripts folder...
@Url.Content("~/relative path to js file")
bruce (sqlwo...
All-Star
36656 Points
5438 Posts
Re: JS application location per view
Nov 18, 2012 09:17 PM|LINK
as view folders are not exposed to http, there is no point in putting them there. you should look at one of the javascript AMD libraries like require.js, and use its structure.