Separating JavaScript in cshtml razor views

前端 未结 6 1875
半阙折子戏
半阙折子戏 2021-01-02 17:46

I\'m new to ASP.NET/MVC3 and I\'m trying to figure out how to separate my JavaScript (which contains C#) from the rest of the HTML.

If I put them into .JS files and

6条回答
  •  抹茶落季
    2021-01-02 18:07

    Javascript code should not contain any dynamically generated code. If you need to load in certain config settings you should use a single inline script tag which defines the variables. Other options are loading in a json config file which is dynamically generated or basing it on dom content depending on the specific dynamic information you need. (Ajax being the most common way I would say, though that really would depend on your situation). Either way, the idea is that javascript and css files are always static.

提交回复
热议问题