Pages

Monday, April 5, 2021

How to return multiple models in a single view in MVC?

Recently I got this question in one of my interviews. Although I have a single answer for this, but interviewers want more ways to return the multiple models in a single view. So I googled this after my interview and found the following ways to do it:

  1. Creating a new view model that consists of all these model classes
  2. Using Partial Classes
  3. Using ViewBag
  4. Using ViewData
  5. Using Dynamic Model
  6. Using Tuple

I will create small-small code snippets for these and will publish them soon here only.