I'm working on a simple web app with 2 Models - Company & Customer. I've created a View Model for these 2 classes that passes both their data to the view. My next step is to configure the controller so the user can edit both models from the same view.
I've modified the Index() + Edit() methods (both have the same code)
public async Task<IActionResult> Index(int? id)
{
var viewModel = new BusinessViewModel();
viewModel.Companies = await _context.Companies
.AsNoTracking()
.ToListAsync();
viewModel.Customers = await _context.Customers
.AsNoTracking()
.ToListAsync();
if (id != null)
{
ViewData["CompanyID"] = id.Value;
Company Company = viewModel.Companies.Where(
i => i.ID == id.Value).Single();
ViewData["CustomerID"] = id.Value;
Customer Customer = viewModel.Customers.Where(
r => r.CustomerID == id.Value).Single();
}
return View(viewModel);
}
Where I struggle with is updating the EditPost method. How do I configure it so that when the user clicks on "save" both the Company & Customer data are updated & displayed on the view?
Let me know if you need more info. Thanks!