Asp.net MVC3从razor视图访问内部类 [英] Asp.net MVC3 access internal class from razor View

查看:72
本文介绍了Asp.net MVC3从razor视图访问内部类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是重复的问题.我已经搜索过SO,但是我需要另外一件事.

This is not a duplicated question. I've already searched on SO but I need a different thing.

今天是从Razor View访问内部类的一种方法,我知道程序集必须是可见的,并且是.

Is today a way to access an internal class from Razor View, I know that the assembly must be visible and is it yet.

默认情况下,无法从Views访问内部"类中声明的属性或方法.我需要一种方法来覆盖它.

No properties nor methods declared in an "internal" class are accessible from Views by default. I need a way to override this.

谢谢.

推荐答案

在大多数情况下,您可以将类从内部更改为公共.您可以在 InternalsVisibleTo 时使用这是不可取的.

In most cases you can change the class from internal to public. You can use the InternalsVisibleTo when that isn't desirable.

对于使用资源( .resx)文件自动生成的 .Designer.cs文件,您可以更改访问修饰符". 公开"通过在设计器"中打开resx文件,在查看:

In the case of .Designer.cs files that are auto-generated with resource (.resx) files, you can change the "Access Modifier" to "public" by opening the resx file in the "Designer" view:

如果其他所有方法均失败,则您应该能够使用反射来获得所需的内容.有关详细信息,请参见此处.那

If all else fails, you should be able to use reflection to get what you need. See the top answer here for details on that

祝你好运!

这篇关于Asp.net MVC3从razor视图访问内部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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