title: How to output MVC / C# object to Javascript object?
body: <p>I have a C# model that gets populated through its constructor. I would like to place this object in my _Layout.cshtml so my Javascript can use it as settings.</p>
  
  <p>Here is what my model looks like:</p>
  
  <pre><code>public class SomeConfig
  {
      public string PropertyA { get; set; }
      public string PropertyB { get; set; }
      public string PropertyC { get; set; }
  
      public SomeConfig()
      {
          PropertyA = SystemSettings.getSetting(KEYA);
          PropertyB = SystemSettings.getSetting(KEYB);
          PropertyC = SystemSettings.getSetting(KEYC);
      }
  }
  </code></pre>
  
  <p>I would like to initialize and output this in _Layout.cshtml so all my other views can use it. So far I am only able to figure out how to do this manually in _Layout.cshtml like this:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      MyNamespace.someConfig = {
          PropertyA: @SystemSettings.getSetting(KEYA),
          PropertyB: @SystemSettings.getSetting(KEYB),
          PropertyC: @SystemSettings.getSetting(KEYC)
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>This is horrible because every time the SomeConfig.cs model gets extended, I have to remember to extend it manually client-side. Is there a way to initialize it in the _Layout.cshtml so it creates a Javascript object dynamically?</p>