ASP.NET MVC: ViewModels versus Domain Entities

后端 未结 6 421
太阳男子
太阳男子 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:34

    Do you have any advice for where to draw the line between domain objects and mere ViewModels?

    Personally I always use View Models. All UI validation logic is done on the view models (required fields, ...) and business logic on the domain models (username already exists, ...). I also use AutoMapper in order to not get tired of mapping between the domain models and the view models that are passed to the view.

提交回复
热议问题