从 ASP.Net MVC 视图访问应用程序设置
在 ASP.Net MVC 1.0 应用程序中,是否可以从我的视图(aspx 页面)内部访问应用程序设置(MyProject.Properties.Settings.Default.*)?
我已经尝试过,但智能感知和编译器不喜欢它。 它说由于保护级别而无法访问。
In an ASP.Net MVC 1.0 applicati0n, is it possible to access the application settings (MyProject.Properties.Settings.Default.*) from inside my View (aspx page)?
I've tried but the intellisense and compiler don't like it. It says that it is inaccesible due to the protection level.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了与 Saajid Ismail 类似的问题,我的设置位于
namespace.Properties.Settings.Default.Setting
中,因为它们是强类型的。为了使它们可访问,我只需更改访问修饰符
I had a similar issue to Saajid Ismail where my settings were in the
namespace.Properties.Settings.Default.Setting
they were there as they are strongly typed..To make them accessible I simply had to change the access modifier
您的视图应该只负责渲染控制器提供给它的数据。 它的职责是布局。 因此,我建议从控制器操作中将应用程序数据传递到视图。
话虽如此,您问题的技术答案是 ViewPage 派生自 Page,因此您可以简单地执行以下操作:
但同样,我不推荐它。
Your View should only be responsible for rendering data given to it by the Controller. It's responsibility is for layout. So I would recommend passing the Application data to the view from within your Controller action.
Having said that, the technical answer to your question is that ViewPage derives from Page, so you can simply do this:
But again, I don't recommend it.