While working on an MVC project, you realize the need to pass both the product details and a list of related reviews to a view. How might you best structure your data to achieve this?

  • Use a ViewModel to combine product details and reviews
  • Pass product details as ViewBag and reviews as ViewData
  • Use a Tuple to combine product details and reviews
  • Embed reviews as a JSON object within the product details
To pass both product details and a list of related reviews to a view, it's best to use a ViewModel. A ViewModel is a dedicated class that combines the necessary data for a view. This approach keeps your code clean, maintainable, and allows for strong typing in your view.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *