How to use .net Resource files in javascript

…衆ロ難τιáo~ 提交于 2019-12-04 06:17:58

If your javascript is in the page you can use:

var globalResource = '<%= Resources.YourClass.YourResourceKey %>';

to access the Global Resources (/App_GlobalResources). Or

var localResource = '<%= GetLocalResourceObject("LocalResourceKey").ToString() %>';

to access the Local resources (/App_LocalResources relative to the page position).

Or a javascript solution may be this nice jQuery plugin.

i did it by using Jquery ajax which calls a serverside GetGlobalResourceObject()

You can just use double quotes in MVC4.

var e = document.getElementById("myelementID");
e.textContent = "@Resource.MyVariable";

I tested and it worked for me.

Is it a separate javascript file? You can always use an asp literal to insert text into your html page (for exemple: var myString = '<asp:literal id="myLiteral" />';) and fill the literal serverside.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!