How to pass multiple objects to view without using ViewData and ViewBag?
Example:
[AllowAnonymous]
public ActionResult RandomView()
{
// Customer.
var customers = _context.Customers.ToList();
List<CustomerDto> customersDto = new List<CustomerDto>();
foreach (var customer in customers)
{
customersDto.Add(new CustomerDto() {
Id = customer.Id,
Name = customer.Name
});
}
// Reports.
var Reports= _context.Reports.ToList();
List<ReportsDto> reportsDto= new List<ReportsDto>();
foreach (var report in reports)
{
reportsDto.Add(new ReportsDto() {
Id = report.Id,
Name = report.Name
});
}
return View(); // How to Pass Both CustomerDto and reportDto ?
}
I want to pass both CustomerDto
& reportDto
as a strongly type to a view. Is it Possible ?