Why Two Classes, View Model and Domain Model?

前端 未结 5 1252
予麋鹿
予麋鹿 2020-11-29 02:47

I know it could be bad to use domain models as view models. If my domain model has a property named IsAdmin and I have a Create controller action to create users, someone co

5条回答
  •  庸人自扰
    2020-11-29 03:41

    Another good reason to have a ViewModel is paging large sets of data. You could pass the view an array of Person ( Person[] ) but metadata such as the number of pages, the number of the current page, the size of the page would not belong on the Person class.

    Therefore a PersonListViewModel would solve this issue.

提交回复
热议问题