title: many to many relationship update data mvc .net core
body: <p>I have a many to many relationship in .net core mvc, but I have no idea how to implement a edit view.</p>
  
  <p>The models are
  Studios</p>
  
  <pre><code>public class Studio
      {
          public int StudioID { get; set; }
          public string Name { get; set; }
          public ICollection&lt;StudioAddress&gt;StudioAddresses { get; set; }
      }
  </code></pre>
  
  <p>Addresses</p>
  
  <pre><code>public class Address
      {
          public int AddressID { get; set; }
          public string Street { get; set; }
          public ICollection&lt;StudioAddress&gt; StudioAddresses { get; set; }
      }
  </code></pre>
  
  <p>StudioAddress</p>
  
  <pre><code>public class StudioAddress
      {        
          public int StudioID { get; set; }
          public Studio Studio { get; set; }
          public int? AddressID { get; set; }
          public Address Address { get; set; }
      }
  </code></pre>
  
  <p>My databasecontext</p>
  
  <pre><code>modelBuilder.Entity&lt;StudioAddress&gt;()
       .HasKey(sa =&gt; new { sa.StudioID, sa.AddressID });
  modelBuilder.Entity&lt;StudioAddress&gt;()
       .HasOne(sa =&gt; sa.Studio)
       .WithMany(s =&gt; s.StudioAddresses)
       .HasForeignKey(sa =&gt; sa.StudioID);
  modelBuilder.Entity&lt;StudioAddress&gt;()
       .HasOne(sa =&gt; sa.Address)
       .WithMany(a =&gt; a.StudioAddresses)
       .HasForeignKey(sa =&gt; sa.AddressID);
  </code></pre>
  
  <p>Now, I have created the edit Get method in my studioscontroller</p>
  
  <pre><code> // get
      public async Task&lt;IActionResult&gt; Edit(int? id)
      {
          if (id == null)
          {
              return NotFound();
          }
  
          var studio = await _context.Studios
               .Include(s =&gt; s.StudioAddresses).ThenInclude(s =&gt; s.Address)
                   .Where(s =&gt; s.StudioID == id)
               .AsNoTracking()
               .FirstOrDefaultAsync();
  
          if (studio == null)
          {
              return NotFound();
          }
          return View(studio);
      }
  </code></pre>
  
  <p>But I have no idea how to update the related data for studio and address?
  Bot are forms with textfields. The <a href="https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/update-related-data?view=aspnetcore-2.2" rel="nofollow noreferrer">original microsoft docs</a> are confusing (they work with tickboxes) and weird methods to whitelist fields. Is there a simpler, more intuitive way of doing this?</p>