How to pass a value from .NET Config File (WebConfig) to Javascript

Jump to: navigation, search

You can pass a value from .NET Config File (WebConfig) to Javascript by following the example below. In Web.Config <configuration> <appSettings> <!--this section probably already exists. Look for it --> <add key = key="myApplicationVersion" value="12.31"/> </appSettings> </configuration> In Your .cshtml @{ ViewBag.ApplicationVersion = (string)System.Configuration.ConfigurationSettings.AppSettings["myApplicationVersion"]; } <html><head> <script type="text/javascript"> var gApplicationVersion = @ViewBag.ApplicationVersion; <script> ... the rest of your head and body HTML code

See also

Personal tools
Namespaces
Variants
Views
Actions
Navigation