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

后端 未结 10 875
生来不讨喜
生来不讨喜 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:29

    Validation must be done in the controller - it's the only place which assures safety and response.

    Validation should be done in the view - it's the point of contact and will provide the best UE and save your server extra work.

    Validation will be done on the model - but only for a certain core level of checks. Databases should always reflect appropriate constraints, but it's inefficient to let this stand for real validation, nor is it always possible for a database to determine valid input with simple constraints.

提交回复
热议问题