Use ASP.NET Resource strings from within javascript files

后端 未结 9 1705
迷失自我
迷失自我 2020-12-13 01:02

How would one get resx resource strings into javascript code stored in a .js file?

If your javascript is in a script block in the markup, you can use this syntax:

9条回答
  •  北海茫月
    2020-12-13 01:26

    In a nutshell, make ASP.NET serve javascript rather than HTML for a specific page. Cleanest if done as a custom IHttpHandler, but in a pinch a page will do, just remember to:

    1) Clear out all the ASP.NET stuff and make it look like a JS file.

    2) Set the content-type to "text/javascript" in the codebehind.

    Once you have a script like this setup, you can then create a client-side copy of your resources that other client-side scripts can reference from your app.

提交回复
热议问题