I’m using ASP.NET MVC 2 and stuck with the situation when needed to store all javascripts in separate javascript files.
But in some pages Javascript’s contains information from server-side, so I need a way to do something like this.
I want to make separate JS files and include them in Site.Master. But still I want to make workable code blocks like this
loadNews("<%= Model.A%>", "<%= Model.B%>");
Is there any way to do some trick?
I’m a newbie on MVC and also facing that situation. I’m dealing with it by calling the javascript functions via a script block on the view.
Something like this:
–On MyFile.js
–On Index.cshtml
Another option could be declare the variables on the view’s script block and referencing those variables on the javascript, since their scope would be global. Would be an ugly thing and a bit harder to mantain, but also could do the job. Like this:
–On MyFile.js
–On Index.cshtml