title: In a create view, insert data at the same time to two different table in ASP.NET MVC?
body: <p>I'm doing an ASP.NET MVC project and I'm having trouble to make the create view work: it doesn't save data into two tables. I'm creating a client with name, email, address, zipcode + city.</p>
  <p>These are my two tables:</p>
  <p><code>Clients</code> table:</p>
  <pre><code>    public int ClientID { get; set; }
      public string Name { get; set; }
      public string Email { get; set; }
      public string Address { get; set; }
      public Nullable&lt;int&gt; MailID { get; set; }
      public virtual PostOffices PostOffices { get; set; }
  </code></pre>
  <p>And then I have <code>PostOffices</code> table:</p>
  <pre><code>    [System.Diagnostics.CodeAnalysis.SuppressMessage(&quot;Microsoft.Usage&quot;, &quot;CA2214:DoNotCallOverridableMethodsInConstructors&quot;)]
      public PostOffices()
      {
          this.Clients = new HashSet&lt;Clients&gt;();
      }
  
      public int MailID { get; set; }
      public string Zipcode { get; set; }
      public string City { get; set; }
  
      [System.Diagnostics.CodeAnalysis.SuppressMessage(&quot;Microsoft.Usage&quot;, &quot;CA2227:CollectionPropertiesShouldBeReadOnly&quot;)]
      public virtual ICollection&lt;Clients&gt; Clients { get; set; }
  </code></pre>
  <p>I have written a controller looking like this:</p>
  <pre><code>    [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Create([Bind(Include = &quot;ClientID,Name,Email,Address,MailID&quot;)] Clients clients)
      {
          if (ModelState.IsValid)
          {
              db.Asiakkaat.Add(asiakkaat);
              db.SaveChanges();
              return RedirectToAction(&quot;Index&quot;);
          }
  
          return View(asiakkaat);
      }
  </code></pre>
  <p>In the view it shows everything and lets me enter data into all of the input boxes, but it only saves data to the <code>Clients</code> table like name, email, address, but it doesn't save anything into the <code>PostOffices</code> table (meaning zipcode and city).</p>
  <p>Is there something wrong with my controller? Or should I somehow add into a client class a zipcode + city, and not the MailID? I can't get it to work.</p>
  <p>I appreciate the help!</p>