title: MVC.Net binding complex models?
body: <p>I have the following code, with an existing customer.
  I need to create a form that created an Order, and pass it to my Controller.</p>
  
  <p>I tried changing my model type on that page to Order instead of Customer, but then I'm gonna have to pass the Order object as well, or at least the OrderId.</p>
  
  <p>Models</p>
  
  <pre><code>public class Customer
  {
     public int Id { set; get; }
     public string FirstName { set; get; }
     public string LastName { set; get; }
     public List&lt;Order&gt; Orders { get; set;}
  }
  
  public class Order
  {
     public int Id { set; get; }
     public string ItemName { set; get; }
     public DateTime SomeDate { set; get; }
  }
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>public class OrderController : Controller
  {
     [HttpPost]
     public Create ActionResult(Customer customer)
     {
        // Customer doesn't have the values that it suppose to have
        // All fields including the array of orders are null
        customerStorage.UpdateOrders(customer);
  
        return ("ItemListPartial", customer.orders);
     }
  }
  </code></pre>
  
  <p>View</p>
  
  <pre><code>@model Company.Application.Model.Customer;
  
  @using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "result" }))
  {
      // How can I bind this to Order object ?
      // I can't define model as Order, because then I need to pass Customer Separately
      @Html.TextBoxFor(o =&gt; o.Orders[0].ItemName)
      @Html.TextBoxFor(o =&gt; o.Orders[0].SomeDate)
      &lt;input type="submit" value="Add" /&gt;
  }
  </code></pre>