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.
Most ASP.NET MVC and Web API apps store their settings in the configuration file's appSettings or connectionStrings elements. Some also use custom configuration sections that can be mapped to a settings class.
settings is located in the My Project folder for Visual Basic projects and in the Properties folder for Visual C# projects. The Project Designer then searches for other settings files in the project's root folder. Therefore, you should put your custom settings file there. If you add a .
To access the setting's value in your code, get the value by indexing into the AppSettings property. The AppSettings property makes it easy to obtain data from the <appSettings> element of your configuration file.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With