如何从剃刀视图访问My.Resources [英] How to access My.Resources from a razor view

查看:137
本文介绍了如何从剃刀视图访问My.Resources的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个剃刀.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆