title: Cannot bind JSon with MVC 3 controller data using KnockoutJS
body: <p>I am new to javascript and MVC 3. I am developing a sample application to get familiar with KnockoutJs. 
       I am passing a c# object with some properties to a controller. Than this object is passed to the View serialized as JSon. Then I am using the data with Knockout in my view and want to return this data back to the server. But the binding with the the server data fails for on of my properties. 
       Here is my code:</p>
  
  <p>Model:</p>
  
  <pre><code>public class FranchiseInfo
      {
          public string FullName { get; set; }
          public string ShortName { get; set; }
          public List&lt;string&gt; ServerIps = new List&lt;string&gt;();
      }
  </code></pre>
  
  <p>Controller with sample data returning JSon to the View:</p>
  
  <pre><code> public JsonResult Data()
          {
              FranchiseInfo franchiseInfo = new FranchiseInfo();
              franchiseInfo.FullName = "PokerWorld";
              franchiseInfo.ShortName = "PW";
              franchiseInfo.ServerIps.Add("192.111.1.3");
              franchiseInfo.ServerIps.Add("192.112.1.4");
  
              return Json(franchiseInfo, JsonRequestBehavior.AllowGet);
          }
  </code></pre>
  
  <p>Javascript file using knockout:</p>
  
  <pre><code>  $(function () {
  
  function viewModel() {
      var self = this;
      self.FullName = ko.observable();
      self.ShortName = ko.observable();
      self.optionValues = ko.observableArray([]);
      self.ServerIps = ko.observableArray([]);
  
      $.getJSON("Home/Data", function (data) {
          self.FullName(data.FullName);
          self.ShortName(data.ShortName);
          self.optionValues([data.FullName, data.ShortName]);
          for (var i = 0; i &lt; data.ServerIps.length; i++) {
              self.ServerIps.push({ name: ko.observable(data.ServerIps[i]) });
          }
      });
  
      self.addIp = function () {
          self.ServerIps.push({ name: ko.observable("0.0.0") });
      }
  
      self.showIps = function () {
          alert(self.ServerIps[name]);
      }
  
      self.save = function () {
          $.ajax({
              url: "Home/Save",
              type: "post",
              data: ko.toJSON({ FullName: self.FullName, ShortName: self.ShortName, ServerIps: self.ServerIp }),
              contentType: "application/json",
              success: function (result) { alert("result") }
          });
      }
  };
  ko.applyBindings(new viewModel);
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>    Full Name:
  &lt;span data-bind="text: FullName"&gt;&lt;/span&gt;
  &lt;input data-bind="value: FullName" /&gt;
  &lt;/div&gt;
  
  &lt;div&gt;
  Short Name:
  &lt;span data-bind="text: ShortName"&gt;&lt;/span&gt;
  &lt;/div&gt;
  
  &lt;select data-bind="options: optionValues"&gt;&lt;/select&gt;
  
  &lt;div data-bind="foreach: ServerIps"&gt;
      Name:
      &lt;input data-bind="value: name" /&gt;
      &lt;span data-bind="text: name" /&gt;
  &lt;/div&gt;
  
  &lt;div data-bind="text: ko.toJSON(ServerIps)"&gt;&lt;/div&gt;
  
  
  &lt;button data-bind="click: addIp"&gt;Add IP&lt;/button&gt;
  
  &lt;button data-bind="click: save"&gt;Save&lt;/button&gt;
  </code></pre>
  
  <p>When Save button is clicked the data is sent to the server in Json format:</p>
  
  <p>Here is the controller:</p>
  
  <pre><code>public JsonResult Save(FranchiseInfo franchiseInfo)
          {
              //some data here
              //return Json result
          }
  </code></pre>
  
  <p>Full name and Short name properties bind correctly with the c# model when I am sending them in Json format back to the server but the ServerIps property which is an array cannot bind. I think because it is in the format { name: ip} and the model property ServerIps is of type List. How can I fix this ? Any help with working example will be appreciated. Thanks.</p>