Hiển thị các bài đăng có nhãn asp.net MVC. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn asp.net MVC. Hiển thị tất cả bài đăng

Thứ Ba, 6 tháng 12, 2016

How to Use ViewModel in Asp.Net MVC with Example

Here we will learn what is viewmodel in asp.net mvc and how to use viewmodel in asp.net mvc applications with example.

ViewModel in Asp.Net MVC

The viewmodel in asp.net mvc represent only the data we want to display on view whether it is used for displaying or for taking input from view. If we want to display more than one model on view in asp.net mvc then we need to create a new viewmodel. Following image shows visual representation of view model in asp.net mvc.
Here we will learn asp.net mvc viewmodel with simple example if we have a Customer entity and Order entity. In view to display both entities (Customer entity + Order entity) data then we need to create viewmodel (CustomerVM) and we will select the properties whichever we want to display from both entities (Customer entity + Order entity) and create a viewmodel.

viewmodel structure in asp.net mvc application

Now start with creating a viewmodel in asp.net mvc before that let's have look on table which we are going to use in our application.