ASP.NET MVC: ViewModels versus Domain Entities

后端 未结 6 446
太阳男子
太阳男子 2020-12-29 12:04

I\'m building a concept application with MVC 3 in an attempt to learn its ways. I\'ve previously done some very heavy-duty applications in WebForms, using an n-tier approach

6条回答
  •  自闭症患者
    2020-12-29 12:57

    My approach is that a ViewModel model should be associated to a single view (or least a set of related views), and is usually a sub-set of your domain model. I see a ViewModel as responsible for UI validation, where as your domain object is responsible for business rule validation.

    As for mapping between the two, highly recommend using Automapper which can automatically map properties based on conventions, it's a huge time saver.

提交回复
热议问题