What is ViewModel?
In ASP.NET MVC, ViewModels are used to shape multiple entities from one or more models into a single object. This conversion into single object provides us better optimization. You can see the concept of ViewModel in the image below.
Where we should use ViewModel?
We can use ViewModel in the following scenarios,
- Managing or creating dropdown lists for a specific entity
- Creating Master-Details View in data-driven websites
- Used in showing shopping carts on the website
- Used in Pagination
- Used in a website to show User profile widget
- Used to make Dashboards for integrating multiple data into one place
- Used as an Aggregate Root to make reports in Domain Driven Design (DDD)
- These are the complex scenarios in which ViewModel can be used for better maintainability, reliability, and testability of code.
For Coding example please refer the below link
https://www.c-sharpcorner.com/article/managing-data-with-viewmodel-in-asp-net-mvc/
No comments:
Post a Comment