Access Global .resx file in ASP.Net View Page

孤者浪人 提交于 2020-01-04 13:45:21

问题


I am currently building in Version 3.5 of the .Net framework and I have a resource (.resx) file that I am trying to access in a web application. I have exposed the .resx properties as public access modifiers and am able to access these properties in the controller files or other .cs files in the web app. My question is this: Is it possible to access the name/value pairs within my view page? I'd like to do something like this...

text="<%$ Resources: Namespace.ResourceFileName, NAME %>"  

or some other similar method in the view page.


回答1:


<%= Resources.<ResourceName>.<Property> %>



回答2:


Expose the resource property you want to consume in the page as a protected page property. Then you can just do use "this.ResourceName"




回答3:


If you are using ASP.NET 2.0 or higher, after you compile with the resource file, you can reference it through the Resources namespace:

text = Resources.YourResourceFilename.YourProperty;

You even get Intellisense on the filenames and properties.



来源:https://stackoverflow.com/questions/62995/access-global-resx-file-in-asp-net-view-page

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