title: mvc how to submit a viewmodel?
body: <p>I currently want a user to update a list of data and be able to submit it back.
  The data the user is updating are similar data, at the moment it is a a handful of textboxes.  They update the information and submit it back.</p>
  
  <p>At the moment I have created the following viewModel</p>
  
  <pre><code>public class Name
  {
      public int Id { get; set; }
      public string FullName { get; set; }
  }
  </code></pre>
  
  <p>This will hold the data.  So from the controller I am mocking the data at the moment</p>
  
  <pre><code>public ActionResult Index()
  {
  
      var listOfNames = new List&lt;Name&gt;();
  
      var name1 = new Name();
      name1.Id = 1;
      name1.FullName = "Test Name1";
  
      var name2 = new Name();
      name2.Id = 2;
      name2.FullName = "Test Name2";
  
      var name3 = new Name();
      name3.Id = 3;
      name3.FullName = "Test Name3";
  
      var name4 = new Name();
      name4.Id = 4;
      name4.FullName = "Test Name4";
  
      listOfNames.Add(name1);
      listOfNames.Add(name2);
      listOfNames.Add(name3);
      listOfNames.Add(name4);
  
      return View(listOfNames);
  }
  </code></pre>
  
  <p>Then the view looks like the following,</p>
  
  <pre><code>@model IEnumerable&lt;MvcApplication1.Models.Name&gt;
  @using (Html.BeginForm())
  {
      foreach (var item in Model)
      {
          @Html.TextBox("namevalues", item.FullName, new { id = "name" + item.Id, data_id = item.Id})
      &lt;br /&gt;
      }
  
      &lt;input type="submit" /&gt;
  }
  </code></pre>
  
  <p>when the user submits the data I would like to have the viewmodel back populated, so that I should be able to do the following</p>
  
  <pre><code>[HttpPost]
  public ActionResult Index(IEnumerable&lt;Name&gt; names)
  {
  
      return View("index", names);
  }
  </code></pre>
  
  <p>Do I need to use javascript to actually collate the info together then pass that? or is there some MVC magic I don't know about?</p>