title: .NET core MVC that uses the EF Framework - Pass the data from one controller another
body: <p>I am doing the first time Web App development using the ASP.NET Core MVC with the EF. I have two tables <code>Customer</code> and <code>Inventory</code> in the SQL Server database.</p>
  <p>I did the <code>Scaffold-DbContext</code> and generated the models/controllers and views for both the tables. My requirement is that from the <code>Customer</code> index page on the each customer on the grid I added a select button, when this select button is clicked I need to pass the selected customer data to the inventory controller and show the customer select on top of the inventory index page and below I showing the grid with the inventory table.</p>
  <p>I am using <code>TempData</code> here. On the customer table I added the select button</p>
  <pre><code>&lt;td&gt;
      &lt;a asp-action=&quot;passToInventory&quot; asp-route-id=&quot;@item.CustomerId&quot;&gt;Select&lt;/a&gt;
  &lt;/td&gt;
  </code></pre>
  <p><code>CustomersController</code>:</p>
  <pre><code>public async Task&lt;IActionResult&gt; passToInventory(int? id)
  {
      if (id == null)
      {
          return NotFound();
      }
  
      Customer customer_data = await _context.Customers.FindAsync(id);
  
      TempData[&quot;custdata&quot;] = customer_data;
  
      return RedirectToAction(&quot;Index&quot;, &quot;Inventories&quot;);
  }
  </code></pre>
  <p>Now on the <code>InventoriesController</code> in the <code>Index</code> method, I made the change like to access the <code>TempData</code> passed</p>
  <pre><code>public async Task&lt;IActionResult&gt; Index()
  {
      Customer cust_data = TempData[&quot;custdata&quot;] as Customer;
      return View(await _context.Inventories.ToListAsync());
  }
  </code></pre>
  <p>I tried to create a model class so I can use both the customer and the inventory list on the <code>Inventory</code> <code>Index</code> page like below:</p>
  <pre><code>public class CustomerInventoryCollectionDataModel
  {
      public Customer CustomerData { get; set; }
      public List&lt;Inventory&gt; Inventorys { get; set; }
  }
  </code></pre>
  <p>I couldn't get the data retrieved on the Index page of the Inventory</p>
  <pre><code> @model IEnumerable&lt;JAXSurplusMouseApp.Models.CustomerInventoryCollectionDataModel&gt;
    
  //show the selected customer data from the previous page 
    unable to access the customer data here and show it 
  
  //table for the Inventory list 
  &lt;tbody&gt;
      @foreach (var item in Model)
      {
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Inventorys.QuantityAvailable)
              &lt;/td&gt;
           &lt;/tr&gt;
       }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/e2ypI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e2ypI.png" alt="enter image description here" /></a></p>
  <p>Please suggest how I can retrieve both the models in the same view and show them in the same page. Any help is greatly appreciated</p>