如何从剃刀视图访问My.Resources [英] How to access My.Resources from a razor view
问题描述
我有一个剃刀.vbhtml视图,并想用字符串资源通常通过My.Resources访问。好像我只能从观点到My.Computer,My.Log和其他几个命名空间,但不My.Resources。我试着改变访问修饰符对公众和增加@Imports,既不工作。
I have a razor .vbhtml view and would like to use string resources normally accessible via My.Resources. Seems like I can only get to My.Computer, My.Log and couple other namespaces from the view, but not My.Resources. I've tried changing access modifier to public and adding @Imports, neither worked.
感谢
推荐答案
添加 Messages.resx
文件到您的项目。在这个文件中在Solution Explorer中集自定义工具= PublicResXFile codeGenerator
的属性。现在视图中可以直接访问资源:
Add a Messages.resx
file to your project. In the properties of this file in the solution explorer set Custom Tool = PublicResXFileCodeGenerator
. Now inside the view you can directly access resources:
@Imports AppName.My.Resources
<div>@Messages.Foo</div>
,这里是包含了所有的截图,你需要:
And here's a screenshot containing all you need:
这篇关于如何从剃刀视图访问My.Resources的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!