Where do you do your validation? model, controller or view

后端 未结 10 876
生来不讨喜
生来不讨喜 2020-12-25 07:52

Where do you put user input validation in a web form application?

  1. View: JavaScript client side
  2. Controller: Server side language (C#...)
  3. Model
10条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-25 08:27

    Simple input validation in the view. Full validation in the model. Reason? If you change your view technology, and the validation is in the view/controller, you have to rewrite your validation for the new view. This can introduce bugs. Put it in the model, and this is reused by all views...

    But, as I said, simple validation in the view for speed and ease.

提交回复
热议问题