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.
Loading...
Related Quiz
- Which file in an ASP.NET Core project acts as the entry point of the application?
- The _______ file in ASP.NET Core Razor views specifies the default layout for the views.
- What is the primary purpose of serving static files in a web application?
- You've been tasked to deploy an ASP.NET Core application to a cloud platform that supports scaling out based on demand, but you want to minimize management overhead. Which service would be the best fit?
- Which feature of EF Core allows developers to execute raw SQL commands directly against the database?