开发者

Embed server side code in the separate JavaScript files

Imagine you have an application that consists C# .NET code for the server side, and JavaScript files on the client side. As you know you can embed server side code by using <% %> tags, or other tags like @ id you are using MVC razor view engine开发者_高级运维.

Now imagine you have separate JavaScript files that are loaded by the script tag in the head tag: how can I embed server side code into the code in the JavaScript files? Is there a way to do this?


Send the header "Content-type: text/javascript" and load it as

<script type="text/javascript" src="whatever.aspx?whatever=someparm"></script>

For example

Response.ContentType = "text/javascript";

or

Response.Headers.Add("Content-type", "text/javascript");

Perhaps you can do this: How to pass variables in to a JS file

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜