从 ASP.Net MVC 视图访问应用程序设置

发布于 2024-07-25 17:56:39 字数 150 浏览 0 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌无敌 2024-08-01 17:56:40

我遇到了与 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
enter image description here

少跟Wǒ拽 2024-08-01 17:56:40

您的视图应该只负责渲染控制器提供给它的数据。 它的职责是布局。 因此,我建议从控制器操作中将应用程序数据传递到视图。

话虽如此,您问题的技术答案是 ViewPage 派生自 Page,因此您可以简单地执行以下操作:

<%= Context.Application["setting"] %>

但同样,我不推荐它。

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:

<%= Context.Application["setting"] %>

But again, I don't recommend it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文