我想從我的web.config中的appsettings檢索一個「imagetype」在JavaScript中。我怎樣才能做到這一點?asp.net mvc c#javascript web.config
5
A
回答
8
您可以在頁面的標記使用下面的代碼:
<script language="JavaScript" type="text/javascript">
var type = '<%= ConfigurationManager.AppSettings["imagetype"] %>';
</script>
1
使用以下命令:
var value = System.Configuration.ConfigurationManager.AppSettings["imagetype"];
您可能會發現,它的工作,你需要添加一個引用到System.Configuration.dll
,如果你不已經有一個。
創建一個新的頁面,並在Page_Load中放線,使這一切寫着:
Response.Clear();
var value = System.Configuration.ConfigurationManager.AppSettings["imagetype"];
Response.Write(value);
Response.End();
您現在可以從Javascript使一個AJAX調用的頁面,也許using ExtJs和文本將返回你的JavaScript。
或者,你可以把下面的到你的頁面:
<script language="javascript" type="text/javascript">
var appSettingValue = '<%=System.Configuration.ConfigurationManager.AppSettings["imagetype"]%>';
// The variable "appSettingValue" will contain the string from your web.config
alert(appSettingValue);
</script>
相關問題
- 1. ASP.NET MVC - web.config文件上的NHaml問題
- 2. ASP.NET MVC煩人的web.config內的bug
- 3. ASP.NET MVC 2和額外的Web.config文件中的Web.config轉換
- 4. 幫助清理asp.net mvc web.config文件
- 5. Azure ASP.NET MVC Web.Config部署問題
- 6. ASP.NET MVC和兩個Web.config文件
- 7. ASP.NET MVC 3個區域,並在web.config中
- 8. asp.net mvc javascript postback
- 9. asp.NET Web.config
- 10. ASP.NET web.config錯誤
- 11. 的web.config在asp.net
- 12. C#MVC ASP.NET DropDownListFor
- 13. ASP.Net MVC,使用JavaScript
- 14. asp.net 4.0 web.config繼承
- 15. 住asp.net web.config設置
- 16. ASP.NET Web.config調試
- 17. ASP.NET SMTP + web.config
- 18. ASP.NET Web.config問題
- 19. 在asp.net中的Web.config?
- 20. IIS/MVC web.config重寫
- 21. 截斷ASP.NET MVC C#
- 22. C#asp.net mvc 1.0 routing
- 23. ASP.NET MVC + Javascript(調用與JavaScript變量的C#代碼)
- 24. asp.net web.config gloablization不工作
- 25. 如何以編程方式修改ASP.NET MVC和C#應用程序中的web.config?
- 26. ASP.NET C#,Javascript
- 27. log4javascript web.config
- 28. 沒有Javascript ASP.NET MVC - 日曆
- 29. ASP.Net MVC ParitalView和Javascript/jQuery?
- 30. asp.net mvc動態javascript菜單
這是MVC ... ...有沒有...的Page_Load – 2010-08-02 14:29:07
@ŁukaszW.pl,是的,但一般的要點是一樣的。出於某種原因,我的眼睛在「asp.net」之後停止閱讀 - 今天是漫長的一天! =) – Rob 2010-08-02 14:35:10