开发者

How to access My.Resources from a razor view

开发者 https://www.devze.com 2023-03-18 07:40 出处:网络
I have a razor .vbhtml view and w开发者_如何学Could 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

I have a razor .vbhtml view and w开发者_如何学Could 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.

Thanks


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:

How to access My.Resources from a razor view

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号