Where do you put your validation in asp.net mvc 3?

后端 未结 5 1125
逝去的感伤
逝去的感伤 2021-02-03 15:26

One common recommended practice in asp.net mvc is that you should not send your business models to your views.. instead you should create viewmodels specific to each view.

5条回答
  •  臣服心动
    2021-02-03 15:46

    Given that you always pass viewmodels to your view and your domain models are not exposed to the end user through views then i don't see any need for validating domain model itself. For example if you receive PersonViewModel from view through form post you will transform it to Person Model (perhaps through automapper etc.) only if PersonViewModel is valid itself. So i believe that input validations should stay with the view models because they are the one that are bound to input.

提交回复
热议问题