MVC-在哪里实现表单验证(服务器端)?

问题描述:

在对传统的MVC应用程序进行编码时,对服务器端表单验证进行编码的最佳实践是什么?代码是属于控制器层还是模型层?为什么呢?

In coding a traditional MVC application, what is the best practice for coding server-side form validations? Does the code belong in the controller, or the model layer? And why?

来自*:

模型视图控制器(MVC)是一种用于软件工程的架构模式.模式的成功使用将业务逻辑与用户界面考虑隔离开来,从而使应用程序更容易修改应用程序的外观或基础业务规则,而又不影响其他规则.在MVC中,模型代表应用程序的信息(数据)和用于操纵数据的业务规则;该视图对应于用户界面的元素,例如文本,复选框项目等;控制器管理与通讯相关的详细信息,以与诸如击键和鼠标移动之类的用户动作模型进行通信.

Model-view-controller (MVC) is an architectural pattern used in software engineering. Successful use of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other. In MVC, the model represents the information (the data) of the application and the business rules used to manipulate the data; the view corresponds to elements of the user interface such as text, checkbox items, and so forth; and the controller manages details involving the communication to the model of user actions such as keystrokes and mouse movements.

因此,模型-它包含应用程序和业务规则.

Thus, model - it holds the application and the business rules.