Access C# variable in javascript file .js

后端 未结 3 1666
我寻月下人不归
我寻月下人不归 2021-01-19 05:08

Is it possible to create a javascript file with some C# variables? Something like this:

var foo =  <%= CODE_VALUE.foo %>;

Or do I hav

3条回答
  •  误落风尘
    2021-01-19 05:46

    Javascript files are static files, and served by the web server statically as well, without processing them with ASP.NET.

    So if you really want to insert that value, you can create an empty .aspx page and include all the javascript in there, and then include the .aspx page in script src.

    But I would probably prefer to have a web service instead, with a web method which you would call from javascript every time you need to receive the value.

提交回复
热议问题