简体   繁体   English

如何在<script> _Layout.cshtml中使用properties.settings.default

[英]How to use properties.settings.default in <script> _Layout.cshtml

We are trying to use the general properties.settings in our cshtml layout page. 我们正在尝试在cshtml布局页面中使用常规properties.settings。 The var setting is in the tag (jQuery) var设置在标签中(jQuery)

We are able to reach the properties.settings.default.OurSetting in our controller. 我们可以在控制器中访问properties.settings.default.OurSetting

We looked at a few questions on SO but they only gave examples to reach it in the controller. 我们在SO上查看了几个问题,但他们只给出了在控制器中实现它的示例。

ex: Best practice to save application settings in a Windows Forms Application ex: 在Windows窗体应用程序中保存应用程序设置的最佳实践

How to use settings in Visual C# 如何在Visual C#中使用设置

http://www.codeproject.com/Articles/17659/How-To-Use-the-Settings-Class-in-C http://www.codeproject.com/Articles/17659/How-To-Use-the-Settings-Class-in-C

So we are tried to do 所以我们试图这样做

var setting = '@(MyProjectName.Properties.Settings.Default.OurSetting)'

But that says the name Properties does not exist in the current context. 但是,这表示当前上下文中不存在名称Properties。

EDIT 编辑

We used the appSettings from the web.config first but because we want to be able to change the setting w/o reloading the app. 我们首先使用web.config中的appSettings,但因为我们希望能够在不重新加载应用程序的情况下更改设置。

将Settings.Designer的访问修饰符从内部更改为公共。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM