I’m looking for a way to populate more than 1 table in MVC, because the method only allows me to return One ModelView or I don’t know how to return more. Do I have to build the table in the controller and store into a ViewData and display the viewData in the page?
Edit: Sorry, I think I didn’t express the idea. The point is that I want to populate 2 or more datatables in the page.
For example, if I have a Customer and that Customer has 5 Contacts and 5 Addresses, I want to display the Customer Information and 2 Tables with Contacts and Addresses.
for each p in modelview
{
"<td>" + p.Name + "</td>"
}
for each p2 in modelview2
{
"<td>" + p2.Product + "</td>"
}
You can return more than one model, but it will require a compound model for the view and the use of prefixes when binding the controller parameter.
Say you have a View Model that is:
Then in your controller, you would have
And in your view you would use: