title: Binding Model data to Knockout ViewModel?
body: <p>Is it possible to bind data from your model to a knockout viewmodel. Heres an example:</p>
  
  <pre><code>public ActionResult Edit(int id)
  {
      Product product = _db.Products.FirstOrDefault(x=&gt;x.ItemId == id);
      return View(product);
  }
  </code></pre>
  
  <p>Then in the View I would traditionally do something like so:</p>
  
  <pre><code>@model myApp.Models.Product
  
  @using(Html.BeginForm())
  {
      @Html.EditorFor(x=&gt;x.ItemName)
      @Html.ValidationMessageFor(x=&gt;x.ItemName)
  
      &lt;input type="submit" value="Update" /&gt;
  }
  </code></pre>
  
  <p>But with Knockout I would create a <code>EditProductViewModel</code> from where I would do something like:</p>
  
  <pre><code>var EditProductViewModel = {
      ItemName = ko.observable('')
  };
  
  EditProductViewModel.Edit = function() {
      $.ajax({
          url: "Home/Edit",
          data: ko.ToJson(this),
          success: function() {
              // do something
          }
      });  
  };
  
  $(function() {
      ko.applyBindings(EditProductViewModel);
  });
  </code></pre>
  
  <p>And instead of using the Html Helpers I would do something like so in my view:</p>
  
  <pre><code>&lt;form data-bind="submit: Edit"&gt;
      &lt;input type="text" data-bind="value: ItemName" /&gt;
      &lt;input type="submit" value="Update" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>So how can I populate this with the data returned from my controller?</p>