In the asp.net mvc 3 application I have two views which have the same set of javascript functions. Javascript is identical so I want to reorganize this code and extract all the javascript code into .js file in order to include it in both chtml files.
The problem is that one of the javascript functions uses C# code in order to get some data from model. How can I insert C# code into the javascript(.js) file or how can I extract all this code into a separate chtml file and include it in both of the previous?
You can’t natively, or at least you shouldn’t. Both for maintenance and performance reason.
You should instead redesign your javascript to have parameterized methods, and initialize the custom value from your views.
Think like jQuery. A lot of plugins are available, standardized, but they are initialized with specific value on pages that are consuming them.