title: Need to pass initial viewmodel data from ASP.NET MVC to knockout.js
body: <p>I was looking at the Contacts editor sample on the knockout.js website:</p>
  
  <p><a href="http://knockoutjs.com/examples/contactsEditor.html" rel="noreferrer">http://knockoutjs.com/examples/contactsEditor.html</a></p>
  
  <p>The sample works perfectly, but I needed to make two changes to it:</p>
  
  <ul>
  <li>Pass the initial data from ASP.NET MVC 3 controller action method. Here is the code from the server:</li>
  </ul>
  
  <p><strong>Classes</strong></p>
  
  <pre><code>public class Phone
  {
      public string Type { get; set; }
      public string Number { get; set; }
  }
  
  public class Person
  {
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public List&lt;Phone&gt; Phones { get; set; }
  }
  </code></pre>
  
  <p><strong>Sample Controller side code</strong></p>
  
  <pre><code>       List&lt;Phone&gt; phoneList = new List&lt;Phone&gt;();
  
          Person p1 = new Person()
          {
              FirstName = "Abc",
              LastName = "Xyz"
          };
  
          Phone phone1 = new Phone()
          {
              Type = "Home",
              Number = "1111111111"
          };
          Phone phone2 = new Phone()
          {
              Type = "Mobile",
              Number = "1111111112"
          };
  
          phoneList.Add(phone1);
          phoneList.Add(phone2);
  
          p1.Phones = phoneList;
  
          List&lt;Phone&gt; phoneList2 = new List&lt;Phone&gt;();
  
          Person p2 = new Person()
          {
              FirstName = "Pqr",
              LastName = "Stu"
          };
  
          Phone phone3 = new Phone()
          {
              Type = "Home",
              Number = "1111111113"
          };
          Phone phone4 = new Phone()
          {
              Type = "Mobile",
              Number = "1111111114"
          };
  
          phoneList2.Add(phone3);
          phoneList2.Add(phone4);
  
          p2.Phones = phoneList2;
  
          people.Add(p1);
          people.Add(p2);
  
          ViewBag.InitialData = Json(people, JsonRequestBehavior.AllowGet);
  </code></pre>
  
  <ul>
  <li>Apart from rows of contacts that are part of the ViewModel, I also need to pass some data (e.g. ContactListName and ContactListOwner) that doesn't belong to the rows of contacts but to the ViewModel itself. These properties will be shown outside the grid of contacts.</li>
  </ul>
  
  <p>I would really appreciate if someone can help me with this.</p>