title: ASP.NET MVC 3 multiple Models to single Form
body: <p>I'm learning ASP.NET MVC 3 and trying to create a View with a single form which is made up of multiple Models linked together by a foreign key. The end goal is to have the single form insert into all the database tables.</p>
  
  <p>The problem is that I cannot figure out why when I right click to create the View that the form is not auto-generated in the cshtml file. Auto-generated code helps a lot since I have many tables that link together, and many fields which I must validate and insert. If it's not possible to auto-generate the form, what is the most efficient/elegant way to get this done?</p>
  
  <p>Here's a simplification of what I have.</p>
  
  <p>Model:</p>
  
  <pre><code>class Customer
  {
      [Key]
      public UInt64 CustomerId { get; set; }
  
      [Required(ErrorMessage = "Name is required.")]
      [Display(Name = "Customer Name")]
      [MaxLength(50)]
      public string FullName { get; set; }
  }
  
  class CustomerAdditionalDetails1
  {
      [ForeignKey("Customer")]
      public UInt64 CustomerId { get; set; }
  
      [Required(ErrorMessage = "This info is required.")]
      [Display(Name = "Customer Information")]
      [MaxLength(50)]
      public string SomeInfo { get; set; }
  }
  
  class CustomerAdditionalDetails2
  {  // same foreign key as CustomerAddtionalDetails1, but with different properties
  }
  
  class CustomerAdditionalDetails3
  {  // same foreign key as CustomerAddtionalDetails1, but with different properties
  }
  
  ...
  
  public class CustomerModel
  {
      public Customer Customer { get; set; }
      public CustomerAdditionalDetails1 CustomerAdditionalDetails1 { get; set; }
      public CustomerAdditionalDetails2 CustomerAdditionalDetails2 { get; set; }
      public CustomerAdditionalDetails3 CustomerAdditionalDetails3 { get; set; }
      ...
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public ActionResult Submit()
  {
      return View();
  }
  
  [HttpPost]
  public ActionResult Submit(CustomerModel customer)
  {
      return View();
  }
  </code></pre>
  
  <p>Please help!</p>